This is my first Rmarkdown document!
library(readr)
library(dplyr)
library(ggplot2)
library(knitr)
Let’s load the Gapminder data from bioconnector.org.
# this is a comment
gm <- read_csv("data/gapminder.csv")
head(gm)
## Source: local data frame [6 x 6]
##
## country continent year lifeExp pop gdpPercap
## (chr) (chr) (int) (dbl) (int) (dbl)
## 1 Afghanistan Asia 1952 28.801 8425333 779.4453
## 2 Afghanistan Asia 1957 30.332 9240934 820.8530
## 3 Afghanistan Asia 1962 31.997 10267083 853.1007
## 4 Afghanistan Asia 1967 34.020 11537966 836.1971
## 5 Afghanistan Asia 1972 36.088 13079460 739.9811
## 6 Afghanistan Asia 1977 38.438 14880372 786.1134
The mean life expectancy is 59.4744394 years.
The years surveyed in this data include: 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007.
ggplot(gm, aes(gdpPercap, lifeExp)) + geom_point()
“kabled” output:
kable(head(gm))
| country | continent | year | lifeExp | pop | gdpPercap |
|---|---|---|---|---|---|
| Afghanistan | Asia | 1952 | 28.801 | 8425333 | 779.4453 |
| Afghanistan | Asia | 1957 | 30.332 | 9240934 | 820.8530 |
| Afghanistan | Asia | 1962 | 31.997 | 10267083 | 853.1007 |
| Afghanistan | Asia | 1967 | 34.020 | 11537966 | 836.1971 |
| Afghanistan | Asia | 1972 | 36.088 | 13079460 | 739.9811 |
| Afghanistan | Asia | 1977 | 38.438 | 14880372 | 786.1134 |
gm %>%
filter(continent=="Oceania") %>%
group_by(country) %>%
summarize(meanlife=mean(lifeExp)) %>%
kable()
| country | meanlife |
|---|---|
| Australia | 74.66292 |
| New Zealand | 73.98950 |
This is for reproducibility! Yay reproducibility!
sessionInfo()
## R version 3.2.3 (2015-12-10)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: OS X 10.10.5 (Yosemite)
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.12.3 ggplot2_2.1.0 dplyr_0.4.3 readr_0.2.2
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.3 digest_0.6.9 assertthat_0.1 plyr_1.8.3
## [5] grid_3.2.3 R6_2.1.2 gtable_0.1.2 DBI_0.3.1
## [9] formatR_1.2.1 magrittr_1.5 scales_0.3.0 evaluate_0.8
## [13] highr_0.5.1 stringi_1.0-1 lazyeval_0.1.10 rmarkdown_0.9.2
## [17] labeling_0.3 tools_3.2.3 stringr_1.0.0 munsell_0.4.3
## [21] yaml_2.1.13 parallel_3.2.3 colorspace_1.2-6 htmltools_0.3