I'm looking at simple way of simplifying code.
Example
The sqrt
function could be easily applied to the subset of columns below.
require(magrittr)
mtcars[,-which(colnames(mtcars) %in%
c("mpg", "cyl", "drat", "wt", "carb",
"hp", "qsec", "vs", "am", "gear"))] %<>%
sqrt
Problem
I'm interested in applying other transformations to the subset without the need to type the whole subsetting sequence again.
For instance the code:
mtcars[,-which(colnames(mtcars) %in%
c("mpg", "cyl", "drat", "wt", "carb",
"hp", "qsec", "vs", "am", "gear"))] %<>%
.data * 1000
will return error:
Error in function_list[[k]](value) : could not find function ".data"
Same with syntax using .
. My question is: syntax-wise, how can i get the same effect as in the sqrt
function but applying longer function to the passed subset?