DS4 Song Simulation 4.3
install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
df<-read_csv("Class Playlist Clean DS4 - Sheet1.csv")
## Rows: 175 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Genre, Artist, Song
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
We created columns to show each genres most voted artist, ex.
Yonaguni was voted most in pop/kpop/latin
head(df)
## # A tibble: 6 × 3
## Genre Artist Song
## <chr> <chr> <chr>
## 1 Genre 1 - hiphop/rap 8k When you call
## 2 Genre 2 - pop/kpop/Latin Yonaguni bad bunny
## 3 Genre 1 - hiphop/rap $uicideboy$ Diemonds
## 4 Genre 1 - hiphop/rap $uicideboy$ Not Even Ghosts Are This Empty
## 5 Genre 1 - hiphop/rap 03 Greedo Trap House
## 6 Genre 5 - alt/indie/folk 10,000 Maniacs Trouble Me
We took count of each genres and how many people voted in these
genres
df$Genre <- as.factor(df$Genre)
genre_counts<-df%>%count(df$Genre)
genre_counts
## # A tibble: 6 × 2
## `df$Genre` n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 58
## 2 Genre 2 - pop/kpop/Latin 25
## 3 Genre 3 - house/ska 5
## 4 Genre 4 - rnb/soul 14
## 5 Genre 5 - alt/indie/folk 45
## 6 Genre 6 - country/rock 28
We changed the column of each genres probability
genre_counts<-genre_counts%>%mutate(tprob=n/sum(n))
we have 33% hiphop/rap because we rounded to the decimal
genre_counts$tprob <- round(genre_counts$tprob,2)
genre_counts
## # A tibble: 6 × 3
## `df$Genre` n tprob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 58 0.33
## 2 Genre 2 - pop/kpop/Latin 25 0.14
## 3 Genre 3 - house/ska 5 0.03
## 4 Genre 4 - rnb/soul 14 0.08
## 5 Genre 5 - alt/indie/folk 45 0.26
## 6 Genre 6 - country/rock 28 0.16