library(tidyverse)
hot100 <- read_rds("data-processed/01-hot100.rds")
# peek at the data
glimpse(hot100)
## Rows: 327,895
## Columns: 7
## $ week_id <date> 1958-08-02, 1958-08-02, 1958-08-02, 1958-08-02…
## $ week_position <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
## $ song <chr> "Poor Little Fool", "Patricia", "Splish Splash"…
## $ performer <chr> "Ricky Nelson", "Perez Prado And His Orchestra"…
## $ previous_week_position <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ peak_position <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
## $ weeks_on_chart <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
find artist with most appearances on charts
hot100 %>%
group_by(performer) %>% # group by performer
summarize(
appearances = n()
) %>% # count number of appearances on charts
arrange(appearances %>% desc()) %>% # arrange results from most to least appearances
head(10) # show top 10 results
Use count to find the same results
hot100 %>%
count(performer, name ="appearances", sort = TRUE) %>% # count performers
head(10) # show top 10 results
use group_by and summarize to find artists with most songs to hit number 1
hot100 %>%
filter(week_position == 1) %>% # look for what hit number 1
distinct(song, performer) %>% # get unique entries
group_by(performer) %>% # group results by performer
summarise(no1hits = n()) %>% #count number of rows in groups, name new columns
arrange (no1hits %>% desc()) %>% # sorts from highest to lowest
filter(no1hits >= 7) #limit results to those with 7 or more hits
find same results using count now
hot100 %>%
filter(week_position == 1) %>% #filter to number 1 hits
distinct(song, performer) %>% # get unique entries
count(performer, name = "no1_hits", sort = TRUE) %>% # count by performer, sort top to bottom
filter(no1_hits >= 7) # limit to 7 or more
Find artists with the most number 1 hits in the last 5 years
hot100 %>%
filter(
week_position == 1,
week_id > "2015-12-31"
) %>% #filter by number 1 hits of last 5 years
distinct(song, performer) %>% # narrow to distinct entries
count(performer, name = "no1_hits", sort = TRUE) %>% # count number of entries
filter(no1_hits > 1) #filter to those that appear more than once
summarize() and group_by()hot100 %>%
filter(
week_position == 1,
week_id > "2015-12-31"
) %>% # filter by number 1 hits in last 5 years
distinct(performer, song) %>% # get unique entries
group_by(performer) %>% # group results by performer
summarise(no1_hits = n()) %>% # count each entries
filter(no1_hits > 1) %>% # filter by those that appear more than once
arrange(no1_hits %>% desc()) # sort most to least
find what performers had the most top 10 hits over all time
hot100 %>%
filter(
week_position <= 10
) %>% # filter for top 10 positions
distinct(song, performer) %>% # get unique entries
group_by(performer) %>% # group results by performer
summarize(number_top_hits = n()) %>% # summarize the amount of times each artist appeared on top ten
arrange(number_top_hits %>% desc()) %>% # sort by most to least appearances
filter(number_top_hits > 19) #limit the results logically
Finding which performer/song combination appeared on the charts the most number of weeks overall
hot100 %>%
count(song, performer, name = "weeks_on_charts", sort = TRUE) %>% # count times performer/song grouping appears
filter(weeks_on_charts > 63) # limit results
Filter for the songs that spent the most weeks at number 1
hot100 %>%
filter(
week_position == 1 # get number 1 hits
) %>%
count(song, performer, name = "weeks_at_number_one", sort = TRUE) %>% # count times songs appeared at the position
filter(weeks_at_number_one > 13) # limit results
hot100 %>%
filter(
week_position == 1 # get number 1 hits
) %>%
count(song, performer, name = "weeks_at_number_one", sort = TRUE) %>% # count times songs appeared at the position
filter(weeks_at_number_one > 13) # limit results