Now I will insert/import our data and imput the first few rows
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
We put the data from the class into the coding, then went to code<Insert Chunck
df <- read_csv("playlist - data_clean.csv")
## Rows: 144 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): genre, artist, title
##
## ℹ 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 title
## <chr> <chr> <chr>
## 1 Genre 1 - hiphop/rap Alesso When I'm Gone
## 2 Genre 1 - hiphop/rap Aliyah's Interlude It Girl
## 3 Genre 1 - hiphop/rap Big Sean Beware
## 4 Genre 1 - hiphop/rap Clipse Ma, I don't love her
## 5 Genre 1 - hiphop/rap Common Be
## 6 Genre 1 - hiphop/rap Drake Nice for what
df %>% arrange(genre)
## # A tibble: 144 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 1 - hiphop/rap Alesso When I'm Gone
## 2 Genre 1 - hiphop/rap Aliyah's Interlude It Girl
## 3 Genre 1 - hiphop/rap Big Sean Beware
## 4 Genre 1 - hiphop/rap Clipse Ma, I don't love her
## 5 Genre 1 - hiphop/rap Common Be
## 6 Genre 1 - hiphop/rap Drake Nice for what
## 7 Genre 1 - hiphop/rap Isaiah Rashad Headshots
## 8 Genre 1 - hiphop/rap Jcole change
## 9 Genre 1 - hiphop/rap Jcole Crooked smile
## 10 Genre 1 - hiphop/rap Jcole Immortal
## # ℹ 134 more rows
2 out 10 these songs are in my playlist
df %>% count(genre)
## # A tibble: 6 × 2
## genre n
## <chr> <int>
## 1 Genre 1 - hiphop/rap 26
## 2 Genre 2 - pop/kpop/Latin 22
## 3 Genre 3 - house/ska 5
## 4 Genre 4 - rnb/soul 43
## 5 Genre 5 - alt/indie/folk 34
## 6 Genre 6 - country/rock 14
This graph tells the numbers of songs in each genre
genre_counts <- df %>% count(genre)
genre_counts <-genre_counts %>% mutate(probability = n/144)
genre_counts
## # A tibble: 6 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 26 0.181
## 2 Genre 2 - pop/kpop/Latin 22 0.153
## 3 Genre 3 - house/ska 5 0.0347
## 4 Genre 4 - rnb/soul 43 0.299
## 5 Genre 5 - alt/indie/folk 34 0.236
## 6 Genre 6 - country/rock 14 0.0972
sample_count <- sample_n(df, 10) %>% count(genre)
sample_count<- sample_count %>% mutate (probability = n/10)
sample_count
## # A tibble: 5 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 3 0.3
## 2 Genre 2 - pop/kpop/Latin 1 0.1
## 3 Genre 3 - house/ska 1 0.1
## 4 Genre 4 - rnb/soul 3 0.3
## 5 Genre 6 - country/rock 2 0.2
sample_count2 <-sample_n(df, 14) %>% count(genre)
sample_count2
## # A tibble: 6 × 2
## genre n
## <chr> <int>
## 1 Genre 1 - hiphop/rap 2
## 2 Genre 2 - pop/kpop/Latin 1
## 3 Genre 3 - house/ska 1
## 4 Genre 4 - rnb/soul 3
## 5 Genre 5 - alt/indie/folk 6
## 6 Genre 6 - country/rock 1
sample_count2<-sample_count2 %>% mutate(probility = n/14)
sample_count2
## # A tibble: 6 × 3
## genre n probility
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 2 0.143
## 2 Genre 2 - pop/kpop/Latin 1 0.0714
## 3 Genre 3 - house/ska 1 0.0714
## 4 Genre 4 - rnb/soul 3 0.214
## 5 Genre 5 - alt/indie/folk 6 0.429
## 6 Genre 6 - country/rock 1 0.0714
sample_count3 <-sample_n(df, 5) %>% count(genre)
sample_count3
## # A tibble: 2 × 2
## genre n
## <chr> <int>
## 1 Genre 4 - rnb/soul 3
## 2 Genre 6 - country/rock 2
sample_count3<-sample_count3 %>% mutate(probility = n/5)
sample_count3
## # A tibble: 2 × 3
## genre n probility
## <chr> <int> <dbl>
## 1 Genre 4 - rnb/soul 3 0.6
## 2 Genre 6 - country/rock 2 0.4
sample_count4 <-sample_n(df, 24) %>% count(genre)
sample_count4
## # A tibble: 6 × 2
## genre n
## <chr> <int>
## 1 Genre 1 - hiphop/rap 4
## 2 Genre 2 - pop/kpop/Latin 6
## 3 Genre 3 - house/ska 1
## 4 Genre 4 - rnb/soul 4
## 5 Genre 5 - alt/indie/folk 7
## 6 Genre 6 - country/rock 2
sample_count4<-sample_count4 %>% mutate(probility = n/24)
sample_count4
## # A tibble: 6 × 3
## genre n probility
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 4 0.167
## 2 Genre 2 - pop/kpop/Latin 6 0.25
## 3 Genre 3 - house/ska 1 0.0417
## 4 Genre 4 - rnb/soul 4 0.167
## 5 Genre 5 - alt/indie/folk 7 0.292
## 6 Genre 6 - country/rock 2 0.0833
sample_count4<-sample_count4 %>% mutate(probility = n/24)
sample_count4
## # A tibble: 6 × 3
## genre n probility
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 4 0.167
## 2 Genre 2 - pop/kpop/Latin 6 0.25
## 3 Genre 3 - house/ska 1 0.0417
## 4 Genre 4 - rnb/soul 4 0.167
## 5 Genre 5 - alt/indie/folk 7 0.292
## 6 Genre 6 - country/rock 2 0.0833