Basics
if (!require("pacman")) install.packages("pacman")## Warning: package 'pacman' was built under R version 3.5.1
pacman::p_load("data.table", "devtools", "dplyr","ggplot2", "shiny", "MASS")
install_github("StatsWithR/statsr")
library(statsr)data(arbuthnot)
names(arbuthnot)## [1] "year" "boys" "girls"
dim(arbuthnot)## [1] 82 3
arbuthnot$boys## [1] 5218 4858 4422 4994 5158 5035 5106 4917 4703 5359 5366 5518 5470 5460
## [15] 4793 4107 4047 3768 3796 3363 3079 2890 3231 3220 3196 3441 3655 3668
## [29] 3396 3157 3209 3724 4748 5216 5411 6041 5114 4678 5616 6073 6506 6278
## [43] 6449 6443 6073 6113 6058 6552 6423 6568 6247 6548 6822 6909 7577 7575
## [57] 7484 7575 7737 7487 7604 7909 7662 7602 7676 6985 7263 7632 8062 8426
## [71] 7911 7578 8102 8031 7765 6113 8366 7952 8379 8239 7840 7640
arbuthnot$girls## [1] 4683 4457 4102 4590 4839 4820 4928 4605 4457 4952 4784 5332 5200 4910
## [15] 4617 3997 3919 3395 3536 3181 2746 2722 2840 2908 2959 3179 3349 3382
## [29] 3289 3013 2781 3247 4107 4803 4881 5681 4858 4319 5322 5560 5829 5719
## [43] 6061 6120 5822 5738 5717 5847 6203 6033 6041 6299 6533 6744 7158 7127
## [57] 7246 7119 7214 7101 7167 7302 7392 7316 7483 6647 6713 7229 7767 7626
## [71] 7452 7061 7514 7656 7683 5738 7779 7417 7687 7623 7380 7288
ggplot(data = arbuthnot, aes(x = year, y = girls)) + geom_line()arbuthnot <- arbuthnot %>% mutate(total = boys + girls)
ggplot(data = arbuthnot, aes(x = year, y = total)) + geom_line() + geom_point()# loading another data
data(present)
dim(present)## [1] 74 3
range(present$year)## [1] 1940 2013
# adding new variable in df
present <- present %>% mutate(total = boys + girls)
present <- present %>% mutate(prop_boys = boys/total)
ggplot(data = present, aes(x = year, y = prop_boys)) + geom_line()present <- present %>% mutate(more_boys = boys > girls)
present <- present %>% mutate(prop_boy_girl = boys/girls)
ggplot(data = present, aes(x = year, y = prop_boy_girl)) + geom_line()# mutate(total = ?) %>%
# arrange(desc(total))- [Data wrangling cheatsheet](http://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf)
- [Data visualization cheatsheet](http://www.rstudio.com/wp-content/uploads/2015/12/ggplot2-cheatsheet-2.0.pdf)
- [R Markdown](http://www.rstudio.com/wp-content/uploads/2016/03/rmarkdown-cheatsheet-2.0.pdf)
- [DataCamp](https://www.datacamp.com/courses).