-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathp2c1-included-datasets.qmd
105 lines (75 loc) · 2.64 KB
/
p2c1-included-datasets.qmd
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
104
105
# Included Datasets
R comes with a variety of datasets already built in. This chapter will teach you how to view the catalog of included datasets, preview individual datasets, and begin working with the data.
## View Catalog
You can view the complete list of datasets available along with a brief description for each one by typing "data()" into your console.
```{r}
#| eval: false
data()
```
This will open a new tab in your RStudio instance that looks similar to the following image:
```{r out.extra="style='background-color: #9ecff7; padding:10px; display: block; margin-left: auto; margin-right: auto; width: 90%;'"}
#| label: data
#| echo: false
#| out.width: 500
knitr::include_graphics("images/data-acquisition/data.png", dpi = 270)
```
## Working with Included Data
The first step to begin working with your chosen dataset is to load it into your environment by using the "data" function with the quoted name of your dataset inside the parentheses. In the following example, we'll attach the "iris" dataset to our environment.
::: callout-note
It may not be necessary for you to load your dataset via the "data" function prior to using it. Additionally, some datasets may require you to add them to your search path by using using the "attach" function (conversely, you can remove datasets from your search path by using the "detach" function).
:::
```{r}
#| eval: false
data("iris")
```
This command will add a new object "iris" to our R session. Let's preview the "iris" dataset by using the "head" function.
```{r}
#| eval: false
head(iris)
```
```{r}
#| echo: false
knitr::kable(head(iris), format="markdown")
```
Finally, you can view more information about any given dataset by typing its name into the "Help" tab in the "Files" pane.
```{r out.extra="style='background-color: #9ecff7; padding:10px; display: block; margin-left: auto; margin-right: auto; width: 90%;'"}
#| label: data-acq-1
#| echo: false
#| out.width: 500
knitr::include_graphics("images/data-acquisition/data-acq-1.png", dpi = 270)
```
## Common Datasets
Here are a few other datasets commonly used in the R community to practice and to teach.
### mtcars
```{r}
#| eval: false
head(mtcars)
```
```{r}
#| echo: false
knitr::kable(head(mtcars), format="markdown")
```
### faithful
```{r}
#| eval: false
head(faithful)
```
```{r}
#| echo: false
knitr::kable(head(faithful), format="markdown")
```
### ChickWeight
```{r}
#| eval: false
head(ChickWeight)
```
```{r}
#| echo: false
knitr::kable(head(ChickWeight), format="markdown")
```
### Titanic
```{r}
head(Titanic)
```
## Resources
- List of datasets available in Base R: <https://www.rdocumentation.org/packages/datasets/versions/3.6.2>