DS4 Song Simulation

Cosmin Wasson Simon

We need to load tidyverse

{r} install.packages("tidyverse")

{r} library(tidyverse)

{r} df <- read_csv("Playlist - Clean.csv") #check first few rows of data {r} head(df) # change variable type to factor {r} as.factor(df$Genre) # get the counts for each genre {r} df %>% count(Genre) ###Now I’m going to save this data frame so I can easily access it again later. {r} Genre_counts <- df %>% count(Genre)

{r} Genre_counts #Modeling ##Calculate Theoretical Probabilities ###Next I need to find the theoretical probabilities of getting each genre by creating a new column in my genre counts table. {r} Genre_counts <- Genre_counts %>% mutate(prob = n/sum(n)) Genre_counts ###I don’t like all those long decimal numbers, so I’m going to round them to 2 decimal places. {r} Genre_counts$prob <- round(Genre_counts$prob, 2) Genre_counts ###This new table tells me that there is an 33% chance of getting a hiphop/rap song, a 14% chance of getting a pop/kpop/Latin song, a 3% chance of getting a house/ska song, a 8% chance of getting an rnb/soul song, a 26% chance of getting an alt/indie/folk song, and a 16% chance of getting a country/rock song.