forked from mccallpitcher/LearnR-2-Spring2026
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_inclass_exercises.qmd
More file actions
62 lines (37 loc) · 1.45 KB
/
01_inclass_exercises.qmd
File metadata and controls
62 lines (37 loc) · 1.45 KB
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
---
title: "Learn R Part II In-class Exercises"
format: html
editor: visual
---
Welcome to Quarto! This is where you will try out all of the hands-on exercises in the workshop. Begin by running these first two code chunks:
```{r}
# load packages
library(tidyverse)
```
```{r}
# load data
bowie <- read_csv("data/david_bowie_spotify.csv")
nat_parks <- read_csv("data/nat_parks_visitors.csv")
```
## 00. Quick review
Using an `if_else()` statement, create a new variable in `bowie` that indicates if a song is "long" or "short". Name the variable `long_short`.
Songs are considered "long" if `duration_sec` is greater than 250.
```{r}
```
## 01. How do I aggregate by collapsing?
Using `group_by()` and `summarise()`, calculate average `danceability` by `long_short`.
On average, are David Bowie's longer or shorter songs more "danceable"?
```{r}
```
## 02. How do I aggregate *without* collapsing?
Alter the `bowie` data frame to add a variable that calculates average `tempo` by `album` (without collapsing).
Bonus: Can you determine if the tempo of the song "Changes" is higher or lower than the "Hunky Dory" album average?
```{r}
```
## 03. How do I tidy data?
Pivot the `nat_parks` data frame longer so that year and visitors each make a column.
Hint: Pivot the year columns only. To specify them, you can use either of these structures:
`cols = start:stop`
`cols = -c(column1, column2`)
```{r}
```