/ ## Load tidy Verse

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.4.4     ✔ 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


/ ## Load the class playlist data afer we cleaned and then we import the data into r

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.
## # 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


/ ## Rename the data to df (data frame) for convience so I dont have to write the full file name over again

df <-
  read.csv("playlist - data_clean.csv")


/ ## Make sure my data is correct if I think some data might be faulty i could check here

head(df)
##                  genre             artist                title
## 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


/ ## This finds the total of the amount of genres there are and how many there is

df %>% count(genre)
##                      genre  n
## 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


/ ## Basic summary of the class playlist data

summary(df)
##     genre              artist             title          
##  Length:144         Length:144         Length:144        
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character


/ ## This code finds the probability of a certain genre playing inside of the class playlist

original <- df %>% count(genre) %>% mutate("probability" = n/sum(n))


/ ## This code lets you veiw the class playlist and the probability for a certain genre to be chosen/played

original
##                      genre  n probability
## 1     Genre 1 - hiphop/rap 26  0.18055556
## 2 Genre 2 - pop/kpop/Latin 22  0.15277778
## 3     Genre 3 -  house/ska  5  0.03472222
## 4      Genre 4 -  rnb/soul 43  0.29861111
## 5 Genre 5 - alt/indie/folk 34  0.23611111
## 6   Genre 6 - country/rock 14  0.09722222


/ ## This creates the number of genres in the class playlist into its own data

df2 <- df %>% count(genre)


/ ## This shuffles the playlist into 10 random songs out of the class playlist data

shuffle10 <- sample_n(df,10)


/ ## View the random playlist with 10 songs

shuffle10 %>% count(genre) %>% mutate("probability" = n/sum(n))
##                      genre n probability
## 1     Genre 1 - hiphop/rap 4         0.4
## 2 Genre 2 - pop/kpop/Latin 3         0.3
## 3      Genre 4 -  rnb/soul 2         0.2
## 4 Genre 5 - alt/indie/folk 1         0.1


/ ## This shuffles the playlist into 25 random songs out of the class data

shuffle25 <- sample_n(df,25)


/ ## View the random playlist with 25 songs

shuffle25 %>% count(genre) %>% mutate("probability" = n/sum(n))
##                      genre n probability
## 1     Genre 1 - hiphop/rap 4        0.16
## 2 Genre 2 - pop/kpop/Latin 4        0.16
## 3     Genre 3 -  house/ska 2        0.08
## 4      Genre 4 -  rnb/soul 7        0.28
## 5 Genre 5 - alt/indie/folk 5        0.20
## 6   Genre 6 - country/rock 3        0.12


/ ## This shuffles the playlist into 50 random songs out of the class data

shuffle50 <- sample_n(df,50)


/ ## View the random playlist with 50 songs

shuffle50 %>% count(genre) %>% mutate("probability" = n/sum(n))
##                      genre  n probability
## 1     Genre 1 - hiphop/rap  5        0.10
## 2 Genre 2 - pop/kpop/Latin 12        0.24
## 3     Genre 3 -  house/ska  1        0.02
## 4      Genre 4 -  rnb/soul 13        0.26
## 5 Genre 5 - alt/indie/folk 14        0.28
## 6   Genre 6 - country/rock  5        0.10

—Reflection—

In this coding simulation it helped me understand that if you take a smaller sample or any sample size smaller than the original its probability will not be the same as theoretical probability and when taking a smaller sample size from the orginal its not going to be the same and will differ every time you shuffle. The original theoretical probability will always have the one true probabilty chances compared to its smaller sample sizes. But one thing wont change, the genre which was the most chosen will have the highest probability as theres a highier chance of it getting chosen as in our class playlist rnb/soul and alt/indie/folk have the mojority and have the highest chances of getting played while house/ska being the lowest chance with only 5 songs.The hardest piece of code in my opinion was mutating the functions and turning the original data into other data like coding to try and find the probability of the genres. The code I felt most proudly about was creating sample size and finding their probability chances. Somthing in programing i would like to learn more about would be how to create other data frames and add data frames to and from the original data frame. Somthing differently i would do if i were to do this again would be read the description of the functions in the code cheat sheet instead of trying to test every code in hopes to find the right code. I wouldnt mind doing this again because this coding is pretty fun.