R Markdown

We will use theoretical probability to calculate a spreadsheet that shows our songs, their artists, and the genres. EQ: What is the likelihood of a song of each genre being played?

Intall tidyverse

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.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── 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

Imported csv

df <- read_csv("Playlist 24-25 - Playlist.csv")
## Rows: 105 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.

Count the genres

df %>% count(Genre)
## # A tibble: 5 × 2
##   Genre                        n
##   <chr>                    <int>
## 1 Genre 1 - hiphop/rap        25
## 2 Genre 2 - pop/kpop/Latin    13
## 3 Genre 4 -  rnb/soul         18
## 4 Genre 5 - alt/indie/folk    22
## 5 Genre 6 - country/rock      27

save our table

Genres<-df %>% count(Genre)

Create new column for probability

Genres %>% mutate( prob = n/105)
## # A tibble: 5 × 3
##   Genre                        n  prob
##   <chr>                    <int> <dbl>
## 1 Genre 1 - hiphop/rap        25 0.238
## 2 Genre 2 - pop/kpop/Latin    13 0.124
## 3 Genre 4 -  rnb/soul         18 0.171
## 4 Genre 5 - alt/indie/folk    22 0.210
## 5 Genre 6 - country/rock      27 0.257

Genre 1 is 24% Genre 2 is 12% Genre 3 is 0% Genre 4 is 17% Genre 5 is 21% Genre 6 is 26%