# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages
# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats
# For example, here's several helpful packages to load in 

library(ggplot2) # Data visualization
library(readr) # CSV file I/O, e.g. the read_csv function

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

system("ls ../input")

# Any results you write to the current directory are saved as output.

library(sqldf)


train <- read_csv("../input/train.csv")
test <- read_csv("../input/test.csv")
client <- read_csv("../input/cliente_tabla.csv")
product <- read_csv("../input/producto_tabla.csv")
town <- read_csv("../input/town_state.csv")

weekwise_Venta_uni_hoy = tapply(train$Venta_uni_hoy, train$Semana, sum)
weekwise_Venta_hoy = tapply(train$Venta_hoy, train$Semana, sum)
weekwise_Dev_uni_proxima = tapply(train$Dev_uni_proxima, train$Semana, sum)
weekwise_Dev_proxima = tapply(train$Dev_proxima, train$Semana, sum)
weekwise_Demanda_uni_equil = tapply(train$Demanda_uni_equil, train$Semana, sum)

weekwise_distribution = cbind(weekwise_Venta_uni_hoy,weekwise_Venta_hoy,weekwise_Dev_uni_proxima,weekwise_Dev_proxima,weekwise_Demanda_uni_equil)
write.csv(weekwise_distribution,"weekwise_distribution.csv")