I need to know how can I create in R indexed variables in a data.frame.
Example: I have P1, P2, P3, B1, B2, B3 numeric variables in a data.frame (dat
) and I have to create the new variables: I1=P1/B1, I2=P2/B2 and I3=P3/B3 in the data.frame dat
using a for loop.
Maybe I was not clear, sorry. I have to create variables (100) Ik, And I don't want to write:
dat$I1<-dat$P1/dat$B1
dat$I2<-dat$P2/dat$B2
dat$I3<-dat$P3/dat$B3
...
dat$I99<-dat$P99/dat$B99
dat$I100<-dat$P100/dat$B100
It's surely possible to do something like that:
for(k in 1:100) {
???
}
Thanks a lot!