My data looks like this:
#> Artist Album Year
#> 1 Beatles Sgt. Pepper's 1967
#> 2 Rolling Stones Sticky Fingers 1971
And my question should be quite simple. I'm trying to use rename_if
to prefix only the columns that start with the letter "A". So my desired output is:
#> df1_Artist df1_Album Year
#> 1 Beatles Sgt. Pepper's 1967
#> 2 Rolling Stones Sticky Fingers 1971
You can see that "Year" should not be prefixed.
This is my attempt, but it's not quite working. Am I using starts_with
incorrectly? Should I try break it into two lines so I can understand it more clearly? The purrr style functions I'm still learning, so it's not always intuitive to me yet.
df1 %>% rename_if(starts_with("A"), .funs = ~ paste0(df1, .))
#> Error in df1 %>% rename_if(starts_with("A"), .funs = ~paste0(df1, .)): could not find function "%>%"
Code for data input:
df1 <- data.frame(stringsAsFactors=FALSE,
Artist = c("Beatles", "Rolling Stones"),
Album = c("Sgt. Pepper's", "Sticky Fingers"),
Year = c(1967, 1971)
)