Mutate
Exercise 0:
Delete the #
symbol on the line # music_top200
. This symbol is called a comment, and causes everything to the right of it to be ignored.
Exercise 1:
Currently, the duration
is calculated in seconds.
- Delete (uncomment) the
#
symbol in the code. - Complete the code to convert duration to milliseconds.
hint
> Delete the # symbol. This is called a comment. When it is the first non-blank on a line, it stops that line from being run. > 1 second is 1000 milliseconds. So you would multiply the duration by 1000.country | position | track_name | artist | streams | duration | continent | |
---|---|---|---|---|---|---|---|
0 | Argentina | 1 | Tusa | KAROL G | 1858666 | 200.960 | Americas |
1 | Argentina | 2 | Tattoo | Rauw Alejandro | 1344382 | 202.887 | Americas |
2 | Argentina | 3 | Hola - Remix | Dalex | 1330011 | 249.520 | Americas |
... | ... | ... | ... | ... | ... | ... | ... |
12397 | South Africa | 198 | Black And White | Niall Horan | 11771 | 193.090 | Africa |
12398 | South Africa | 199 | When I See U | Fantasia | 11752 | 217.347 | Africa |
12399 | South Africa | 200 | Psycho! | MASN | 11743 | 197.217 | Africa |
12400 rows × 7 columns
Exercise 2:
Uncomment the mutate in the pipe below. Can you fix the two errors in it?
It should return data with a new column on the right, that divides position by 200.
country | position | track_name | artist | streams | duration | continent | |
---|---|---|---|---|---|---|---|
0 | Argentina | 1 | Tusa | KAROL G | 1858666 | 200.960 | Americas |
1 | Argentina | 2 | Tattoo | Rauw Alejandro | 1344382 | 202.887 | Americas |
2 | Argentina | 3 | Hola - Remix | Dalex | 1330011 | 249.520 | Americas |
... | ... | ... | ... | ... | ... | ... | ... |
12397 | South Africa | 198 | Black And White | Niall Horan | 11771 | 193.090 | Africa |
12398 | South Africa | 199 | When I See U | Fantasia | 11752 | 217.347 | Africa |
12399 | South Africa | 200 | Psycho! | MASN | 11743 | 197.217 | Africa |
12400 rows × 7 columns
Exercise 3:
The mutate below uses code from a future chapter to calculate how many letters are in each artist's name.
Which artist with the shortest name has the most streams?
hint
> You'll need to use an arrange in the pipe with 2 arguments.country | position | track_name | artist | streams | duration | continent | artist_length | |
---|---|---|---|---|---|---|---|---|
0 | Argentina | 1 | Tusa | KAROL G | 1858666 | 200.960 | Americas | 7 |
1 | Argentina | 2 | Tattoo | Rauw Alejandro | 1344382 | 202.887 | Americas | 14 |
2 | Argentina | 3 | Hola - Remix | Dalex | 1330011 | 249.520 | Americas | 5 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
12397 | South Africa | 198 | Black And White | Niall Horan | 11771 | 193.090 | Africa | 11 |
12398 | South Africa | 199 | When I See U | Fantasia | 11752 | 217.347 | Africa | 8 |
12399 | South Africa | 200 | Psycho! | MASN | 11743 | 197.217 | Africa | 4 |
12400 rows × 8 columns
Test yourself
(click to answer)