My data frame is called Subs.
My variables are REV_4, REV_5, REV_6 etc
I want to create new variables to calculate percentage change of revenue.
Eg: d.rev.5 <- Subs$REV_5/Subs/$REV_4 -1
I would like to use a loop to create these new variables. I've tried this:
for(i in 5:10){
Subs$d.data.[i] <- Subs$REV_[i]/Subs$REV_[i-1] - 1 }
But it doesn't work.
I suspect it's not recognizing the i as part of the variable name.
Is there any way to get around this? Thank you so much.
Subs$d.rev.5 <- Subs$REV_5 / (Subs$REV_4 - 1)should do.dput(head(Subs))so others can see the structure of the data you're working with, and can therefore give you a solution