123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- ---
- title: "Explore tidyverse with liftr"
- author: "Nan Xiao <<[email protected]>>"
- date: "`r Sys.Date()`"
- output:
- rmarkdown::pdf_document:
- toc: true
- number_sections: true
- liftr:
- from: "rocker/tidyverse:latest"
- maintainer: "Nan Xiao"
- email: "[email protected]"
- pandoc: false
- texlive: true
- cran:
- - nycflights13
- ---
- \clearpage
- # ggplot2
- The example is from: https://github.com/tidyverse/ggplot2.
- ```{r}
- library("ggplot2")
- ggplot(mpg, aes(displ, hwy, colour = class)) +
- geom_point()
- ```
- # tibble
- The examples are from: https://github.com/tidyverse/tibble.
- ```{r}
- library("tibble")
- as_tibble(iris)
- tibble(x = 1:5, y = 1, z = x ^ 2 + y)
- tribble(
- ~x, ~y, ~z,
- "a", 2, 3.6,
- "b", 1, 8.5)
- ```
- # purrr
- The example is from: https://github.com/tidyverse/purrr.
- ```{r}
- library("purrr")
- mtcars %>%
- split(.$cyl) %>% # from base R
- map(~ lm(mpg ~ wt, data = .)) %>%
- map(summary) %>%
- map_dbl("r.squared")
- ```
- # dplyr
- The examples are from: https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html.
- ```{r}
- library("dplyr")
- library("nycflights13")
- filter(flights, month == 1, day == 1)
- slice(flights, 1:10)
- arrange(flights, year, month, day)
- select(flights, year, month, day)
- mutate(flights,
- gain = arr_delay - dep_delay,
- speed = distance / air_time * 60)
- summarise(flights,
- delay = mean(dep_delay, na.rm = TRUE))
- ```
- # Session information
- The R session information for compiling this document is shown below.
- ```{r session}
- sessionInfo()
- ```
|