-
Notifications
You must be signed in to change notification settings - Fork 1
/
00_import_data.qmd
93 lines (61 loc) · 2.18 KB
/
00_import_data.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
---
title: "Exercise 0"
date-modified: 'today'
date-format: long
format:
html:
footer: "CC BY 4.0 John R Little"
license: CC BY
---
Goals:
- Create a R Notebook
- Import a dataset using `reader::read_csv()`
> ANSWER can be found in exercise_00_answers.Rmd file
## Exercise: Data Structures & Vector Types
1. Load the tidyverse libary package
```{r}
#| message: false
#| warning: false
library(tidyverse)
```
2. Fill in the blanks. Using what you've seen in class, if `data/brodhead_center.csv` is a CSV (comma separated values) file, how would you load the file into a new object called `brodhead`?
- Often people find using the {here} package is helpful . e.g. `read_csv(here::here("data", "file")`
```{r}
_____ <- read_csv(________)
```
3. Display your new `brodhead` data frame?
```{r}
```
4. `starwars` is an on-board dataset that comes with the tidyverse. Insert a new code chunk and display that data.
5. Copy and paste the following code into a new code chunk in your new file.
```{r}
starwars %>%
ggplot(aes(fct_infreq(hair_color))) +
geom_bar() +
ggtitle("Hair color frequency for Star Wars Characters")
```
### BONUS 1
6. Take a look at the structure of the `brodhead` object.
- How many observations (rows) are there?
- How many variables (columns) are there?
- How many of the variables are numeric data?
HINT: You can use the `glimpse()` function
> ANSWER can be found in exercise_00_answers.Rmd file
### BONUS 2
1. Import SPSS data containing labeled vectors: `data/student_satisfaction_test_data_from_qualtrics.sav`
2. Convert the labeled vector field `Q2` to its labeled values with `haven::as_factor()` and `mutate()`
Hints:
- The {`here`} package is helpful for navigating to the data directory
- Notice the data-types of the variables. Using `glimpse()` or simply displaying the data frame, notice the data type: `<S3: haven_labelled>` used for some columns.
```{r}
library(haven)
library(here)
my_labeled_vectors_df <-
read_sav(here("data", "student_satisfaction_test-data_from_qualtrics.sav"))
```
```{r}
my_labeled_vectors_df
my_labeled_vectors_df |>
select(Q2) |>
mutate(Q2_labels = _________(Q2))
```