-
Notifications
You must be signed in to change notification settings - Fork 1
/
intro.Rmd
103 lines (71 loc) · 3.02 KB
/
intro.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Introduction
## What is the "tidyverse"
* A set of packages designed for **data science**:
* Importing data into R
* Preparing / Cleaning data
* Data wrangling (tidying and transforming data)
* Visualizing data
* All packages share **good practices** in terms of:
* Philosophy
* Grammar
* Data structure
## Good reasons to learn (at least a bit) how to use it
* More **intuitive programming**: the names of functions speak for themselves.
* The code is **easier to read** than with R base: it facilitates code sharing.
* More **efficient**: the functions are quite quick (coded more efficiently).
* Very good [**documentation and tutorials**](https://www.tidyverse.org/learn/).
Here is a piece of **R base code**:
```{r class.source="bg-danger", class.output="bg-warning", eval=F}
diamonds2 <- diamonds[diamonds$cut == "Ideal", c("cut", "color", "carat", "price")]
diamonds2[order(diamonds2$price, decreasing=TRUE),]
```
And its equivalent in the **tidyverse**:
```{r df-drop-ok, class.source="bg-success", eval=F}
diamonds %>%
select(cut, color, carat, price) %>%
filter(cut=="Ideal") %>%
arrange(desc(price))
```
## Tidyverse core packages
The following 8 packages are included in the core **tidyverse version 1.3.0.9000** (current version in April 2021):
* Data Import and Management
* tibble
* readr
* Data Wrangling (Tyding and Transformation)
* dplyr
* tidyr
* stringr
* forcats
* Data Visualization and Exploration
* ggplot2
* Functional Programming
* purrr
<br>
```{r, echo=FALSE, eval=TRUE}
tbl_logos <- data.frame(
logo = "",
name = c("dplyr", "tidyr", "stringr", "forcats", "readr", "tibble", "purrr", "ggplot2"),
description=c("Package for data manipulation and exploratory data analysis.",
"Package that aims at creating tidy data. Tidy data describe a standard way of storing data.",
"Package that provides a set of functions for user-friendly string manipulation.",
"Package that helps you deal with factors",
"Package for fast and efficient import and export of data.",
"Tibbles are improved - easier to manage - data frames.",
"Package that aims at enhancing R's functional programming toolkit. It provides a set of tools for working with functions and vectors.",
"Package for data vizualization of graphics based on Leland Wilkinson's' Grammar of Graphics: graphics are built one layer at a time.")
)
tbl_logos %>%
kbl(booktabs = T) %>%
kable_paper(full_width = T) %>%
column_spec(1, image = spec_image(
c("images/dplyr_logo.png", "images/tidyr_logo.png", "images/stringr_logo.png", "images/forcats_logo.png", "images/readr_logo.png", "images/tibble_logo.png", "images/purrr_logo.png", "images/ggplot2_logo.png"), width=380, height=270))
```
## Install and load all tidyverse package
Install (should be done before the class, as it takes a while!):
```{r, eval=FALSE}
install.packages("tidyverse")
```
Load:
```{r, eval=TRUE}
library(tidyverse)
```