Reading input from a csv file leaves me with an odd field containing multiple values e.g.
Title Genres
1 A [Item1, Item2, Item3]
2 B
3 C [Item4, Item1]
df <- data.frame(c("A","B","C"), c("[Item1, Item2, Item3]","","[Item4, Item1]"),
stringsAsFactors = FALSE)
colnames(df) <- c("Title","Genres")
A function to retrieve the individual tokens
extractGenre <- function(genreVector){
strsplit(substring(genreVector,2,nchar(genreVector)-1),", ")
}
I am a bit lost on how to convert Item 1,... Item 4 into factors and append them to the dataframe. While apply lets me execute the function on each row, how would the next step look like?