Skip to content
Prev 311561 / 398503 Next

Efficiently creating/defining new variables transformations

On Nov 21, 2012, at 4:35 PM, nprause wrote:

            
Easiest way would be to use "[[<-" (since there is no 'paste0<-' function:

data[[ paste0(emotions[[i]],"_sqrt") ] <- sqrt(data[[ emotions[i] ]])

Now I'm pretty sure that would not work as it stands if the length of "i" were greater than 1, but if "i" were a single number or character value being delivered inside a loop or equivalently inside sapply(), it should work.

You can also look at:

?assign
David Winsemius, MD
Alameda, CA, USA