-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction_combine_charts.R
50 lines (39 loc) · 1.25 KB
/
action_combine_charts.R
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
# Combine Billboard charts
# Setup
library(tidyverse)
library(fs)
# Charts list
charts_list <- c("hot-100", "billboard-200")
# Combine the files for each chart
for (chart in charts_list) {
# compile a list of files to scrape
files_list <- dir_ls(paste("data-scraped", chart, sep = "/"), recurse = TRUE, regexp = ".csv")
# combine all the files
charts_recent <- map_dfr(files_list, read_csv, col_types = cols("last_week" = col_integer()))
# write the combined file
charts_recent |> write_csv(paste("data-out/", chart, "-current.csv", sep = ""))
# Create assignment data
if (chart == "hot-100") {
hot100_assignment <- charts_recent %>%
# muck the date
mutate(
chart_week = paste(
month(chart_week) %>% as.character(),
day(chart_week) %>% as.character(),
year(chart_week) %>% as.character(),
sep = "/"
)
) |>
# muck the names
select(
`CHART WEEK` = chart_week,
`THIS WEEK` = current_week,
`TITLE` = title,
`PERFORMER` = performer,
`LAST WEEK` = last_week,
`PEAK POS.` = peak_pos,
`WKS ON CHART` = wks_on_chart
)
hot100_assignment |> write_csv("data-out/hot100_assignment.csv")
}
}