I have a spotify$gens
column where it contains all the descriptions of genres of each album.
For example:
head(spotify$gens)
gives
gens = c("Jazz Fusion", "Latin Rock, Progressive Rock", "Progressive Rock",
"Blues Rock, Electric Blues", "Electric Texas Blues, Electric Blues", "Piano Blues, Chicago Blues")
I want to use what I have made:
keyGenres = c("Pop","Rock","Hip Hop","Latin",
"Dance","Electronic","R&B","Country","Folk",
"Acoustic","Classical","Metal","Jazz","New Age",
"Blues","World","Traditional")
to match the spotify$gens
and return the matching part of the string string.
I have this code right now:
for (i in seq_along(spotify$gens)){
for (genre in keyGenres){
if( spotify$gens[i] %ilike% keyGenres[genre]){
spotify$gens[i] <- keyGenres[genre]
} else{
spotify$gens[i] = spotify$gens[i]
}}}
but it is returning me this error:
Error in if (spotify$gens[i] %ilike% keyGenres[genre]) { : missing value where TRUE/FALSE needed
An example result i want would be
spotify$gens[1] = "Jazz Fusion"
to spotify$gens[1] = "Jazz"
Some albums have more than one genre and I want to return the first string that is matched only.
Can anyone help me out? Thank you!!