install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ 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("Playlist_Clean_(2).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.
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
df$Genre <- as.factor(df$Genre)
head(df)
## # A tibble: 6 × 3
## Genre Artist Song
## <fct> <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
df %>% count(Genre)
## # A tibble: 6 × 2
## 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
genre_counts <- df %>% count(Genre)
genre_counts <- genre_counts %>% mutate(prob = n/sum(n))
genre_counts$prob <- round(genre_counts$prob, 2)
genre_counts
## # A tibble: 6 × 3
## Genre n prob
## <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
sample <- sample_n(df,10)
sample
## # A tibble: 10 × 3
## Genre Artist Song
## <fct> <chr> <chr>
## 1 Genre 1 - hiphop/rap Polo G Martin and Gina
## 2 Genre 1 - hiphop/rap drake pipe down
## 3 Genre 1 - hiphop/rap NLE choppa Shotta Flow 3
## 4 Genre 5 - alt/indie/folk Yot club Ykwim?
## 5 Genre 2 - pop/kpop/Latin Taylor Swift Style
## 6 Genre 6 - country/rock VIOLENT MIRA I Don't Care
## 7 Genre 5 - alt/indie/folk Surf Curse Freaks
## 8 Genre 6 - country/rock Three Days Grace I Hate Everything About You
## 9 Genre 5 - alt/indie/folk Arctic Monkeys When the sun comes down
## 10 Genre 2 - pop/kpop/Latin Ice Paper Talking to the moon
sample_counts <- sample %>% count(Genre) %>% mutate(probability = n/sum(n))
sample_n(df, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 4 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 9 0.45
## 2 Genre 3 - house/ska 1 0.05
## 3 Genre 5 - alt/indie/folk 5 0.25
## 4 Genre 6 - country/rock 5 0.25
sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 13 0.43
## 2 Genre 2 - pop/kpop/Latin 1 0.03
## 3 Genre 4 - rnb/soul 2 0.07
## 4 Genre 5 - alt/indie/folk 8 0.27
## 5 Genre 6 - country/rock 6 0.2
sample_n(df, 40) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 18 0.45
## 2 Genre 2 - pop/kpop/Latin 3 0.07
## 3 Genre 3 - house/ska 1 0.03
## 4 Genre 4 - rnb/soul 2 0.05
## 5 Genre 5 - alt/indie/folk 8 0.2
## 6 Genre 6 - country/rock 8 0.2
sample_n(df, 75) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 24 0.32
## 2 Genre 2 - pop/kpop/Latin 11 0.15
## 3 Genre 3 - house/ska 4 0.05
## 4 Genre 4 - rnb/soul 5 0.07
## 5 Genre 5 - alt/indie/folk 23 0.31
## 6 Genre 6 - country/rock 8 0.11
sample_n(df, 86) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 36 0.42
## 2 Genre 2 - pop/kpop/Latin 10 0.12
## 3 Genre 3 - house/ska 3 0.03
## 4 Genre 4 - rnb/soul 7 0.08
## 5 Genre 5 - alt/indie/folk 18 0.21
## 6 Genre 6 - country/rock 12 0.14
sample_n(df, 100) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 35 0.35
## 2 Genre 2 - pop/kpop/Latin 16 0.16
## 3 Genre 3 - house/ska 5 0.05
## 4 Genre 4 - rnb/soul 4 0.04
## 5 Genre 5 - alt/indie/folk 26 0.26
## 6 Genre 6 - country/rock 14 0.14