Problem: I am trying to use mutate, ifelse, and grepl functions to pull out the data from lyrics3. Where every year is stored with artist name, lyrics, and records. I am trying to create a new variable called "decade" and store each year by its decade. Simply put, 1980-1989 is 1980s and so on. But instead function is renaming everything to 2010s and giving me a problem statement saying "argument 'pattern' has length > 1 and only the first element will be used" Here is my code below:
lyrics3 <-lyrics3 %>%
mutate(decade = ifelse(grepl("198", year), "1980s",
ifelse(grepl("199", year), "1990s",
ifelse(grepl("200", year), "2000s", "2010s"))))