[R] passing variable names to dplyr

Dennis Murphy djmuser at gmail.com
Wed Jan 29 00:43:20 CET 2014


David:

I privately suggested he post to manipulatr because Hadley is more
likely to see his question there first than in R-help. He originally
posted here, noted the cross-posting and referral at manipulatr and
responded back to this list when he got a successful reply from
Hadley. I don't see that he's done anything wrong; in fact, he's been
exceptionally polite. If you want to yell at anybody, yell at me.

Dennis

On Tue, Jan 28, 2014 at 3:33 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list