I want to generate multiple new columns based on the current variable information in the data.frame (eg. data here), I can generate the variables with the loops using the scripts I listed below, is it possible to create them with the mutate
command in dplyr with concise command? For example, using the mutate together with function, apply function or loop?
The requirement seems different from what have been achieved here Mutating multiple columns in a data frame using dplyr and Mutate multiple / consecutive columns (with dplyr or base R) as I want to create dozens of new columns with certain pattern based on one original variable.
data=data.frame(value=1:11,EV=seq(100,150,5))
q<-seq(-0.5,0.5,0.1)
data
EV=rep(NA,11)
for (i in 1:11){
value=assign(paste0('EV',i),data[,'EV']*(1+q[i]))
EV=cbind(EV,value)
}
EV=data.frame(EV[,2:12])
names(EV)<-paste0('EV',1:11)
EV
data.frame(data,EV)