Extract the unique genres and its count and store in data frame with index key

Viewed 234

How do you split the multiple values of a variable in R programming. Image with column GenreLike, in the image the genre has multiple values in it's cells. how do you separate them and get count of the values in a table.

2 Answers

We can use separate_rows

library(dplyr)
library(tidyr)
df1 %>%
  separate_rows(Genre) %>%
  count(Genre)

Or using base R

table(unlist(strsplit(df$Genre, ",\\s*")))
table(trimws(unlist(strsplit(df$Genre, split = ","))))
Related