How do add numbers to columns using `rename_at`?

Here I want to rename all the cat columns to be cat_1, cat_2, and cat_3 respectively. How do I do this using rename_at?

tibble("cat" = "meow", 
       "cats" = "meow", 
       "catss" = "meow", 
       "dog" =  "woof") %>% 
  rename_at(vars(starts_with("cat")), .funs = ???)
tibble("cat" = "meow", 
       "cats" = "meow", 
       "catss" = "meow", 
       "dog" =  "woof") %>% 
  rename_at(vars(starts_with("cat")), .funs = ~paste0("cat_", 1:length(.)))
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.