library(tidyverse) andmed=read_csv("http://archive.ics.uci.edu/ml/machine-learning-databases/00396/Sales_Transactions_Dataset_Weekly.csv") colnames(andmed) andmed %>% select(W0:W51) andmed %>% select(W0:W51) %>% summarise_all(sum) nsummad=andmed %>% select(W0:W51) %>% colSums() max(nsummad) nsummad[nsummad==max(nsummad)] which(nsummad==max(nsummad)) arvud=unname(nsummad) which(arvud==max(arvud)) colnames(andmed)[which(arvud==max(arvud))+1] andmed %>% select(W0:W51) %>% rowSums() summad=andmed %>% select(W0:W51) %>% rowSums() andmed %>% select(Product_Code) %>% mutate(aasta=summad) andmed %>% select(W0:W10, W41:W51) #Leia talvised kogused talvesummad=andmed %>% select(W0:W10, W41:W51) %>% rowSums() #Leia suvised kogused suvesummad=andmed %>% select(W15:W35) %>% rowSums() andmed %>% select(Product_Code) %>% mutate(suvi=suvesummad, talv=talvesummad) andmed %>% select(Product_Code) %>% mutate(suvi=suvesummad, talv=talvesummad) %>% mutate(suhe=suvi/talv) %>% arrange(-suhe) %>% filter(suvi>10) %>% head(20) %>% View() andmed[1, 2:52] #plot(andmed[1, 2:12]) tibble(myyk=unname(andmed[2:52])) %>% ggplot(aes(y=myyk)) + geom_line() names(andmed[1, 2:52]) as.numeric(andmed[1, 2:52]) tabel=tibble(nadal=names(andmed[1, 2:52]), tulemus=as.numeric(andmed[1, 2:52])) tabel %>% tail() tibble(tulemus=as.numeric(andmed[1, 2:52])) %>% ggplot(aes(1:51, tulemus))+geom_line() suvetooted = andmed %>% select(Product_Code:W51) %>% mutate(suvi=suvesummad, talv=talvesummad) %>% mutate(suhe=suvi/talv) %>% arrange(-suhe) %>% filter(suvi>10) %>% head(20) suvetooted %>% gather(nadal, kogus, -Product_Code) suvetooted %>% gather(nadal, kogus, -Product_Code) %>% mutate(nnr=as.numeric(substr(nadal, 2, 4))) suvetooted %>% gather(nadal, kogus, -Product_Code) %>% mutate(nnr=as.numeric(substr(nadal, 2, 4))) %>% ggplot(aes(nnr, kogus, color=Product_Code))+geom_line() + ylim(0, 20) + theme(legend.position="none") #Tehke sarnane joonis talvetoodete kohta talvetooted = andmed %>% select(Product_Code:W51) %>% mutate(suvi=suvesummad, talv=talvesummad) %>% mutate(suhe=suvi/talv) %>% arrange(suhe) %>% filter(talv>10) %>% head(20) talvetooted talvetooted %>% gather(nadal, kogus, -Product_Code) %>% mutate(nnr=as.numeric(substr(nadal, 2, 4))) %>% ggplot(aes(nnr, kogus, color=Product_Code))+geom_line() + ylim(0, 20) + theme(legend.position="none") andmed %>% select(Product_Code:W51) %>% mutate(suvi=suvesummad, talv=talvesummad) %>% mutate(suhe=suvi/talv) %>% arrange(suhe) %>% mutate(aastaaeg=ifelse(suhe>1.5, "suvine", ifelse(suhe<0.75, "talvine", "muu"))) %>% select(Product_Code, W0, aastaaeg) %>% View()