[R] passing variable names to dplyr

David Winsemius dwinsemius at comcast.net
Wed Jan 29 00:33:39 CET 2014


On Jan 27, 2014, at 7:45 AM, Bos, Roger wrote:

> All,
> 
> I would like to figure out how to pass variable names to the dplyr function mutate.  For example, this works because hp is one of the variable names on mtcars:
> 
> mutate(mtcars, scale(hp))
> 
> Let's says I want to pass in the target variable instead of hard-coding the name, as follows:
> 
> target <- "hp"
> mutate(mtcars, scale(target))
> 
> That dones't work.  I read somewhere about using lapply, but that suggestion didn't work for me either:
> 
> target <- lapply("hp", as.symbol)
> mutate(mtcars, scale(target))
> 
> Does anyone know how to do this?

You cross-posted this to the manipulatr newsgroup (where it was addressed). Crossposting is a practice which is not appreciated in R lists.

--

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list