Hi,
I have the following data frame called data:
country dog_2021 cat_2022 dog_2021 cat_2022
1 Norway 1 4 7 2
2 UK 2 5 8 2
3 USA 3 6 9 2
I want the columnames of this data frame to update for every new year that comes by, a so called rolling time window.
So, when the next year comes, it will be
country dog_2022 cat_2023 dog_2022 cat_2023
1 Norway 1 4 7 2
2 UK 2 5 8 2
3 USA 3 6 9 2
I would like this change to happen without the need to update the name of each column manually.. Any suggestions?
Also, I need to multiply all the columns by 1.25, except from the first column, which only contains characters. Ideally it would be something like this:
thisyear <- 2022
lastyear <- 2021
new_data <- data %>%
mutate_at(vars((paste(dog, lastyear, sep =""):paste(cat, thisyear, sep="")),
.funs = funs(. * 1.25)))
But when I run this code, it doesn't work out. Does anyone have an idea to solve this problem?
Thank you so much in advance!