[R] passing variable names to dplyr
David Winsemius
dwinsemius at comcast.net
Wed Jan 29 01:25:58 CET 2014
On Jan 28, 2014, at 3:43 PM, Dennis Murphy wrote:
> 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.
And after I replied I saw that he also posted a "solved" message in rhelp, a courtesy I do heartily endorse, so thank you, Roger. (If it were posted as a reply to his original question, I would not have sent anything. I didn't think I was yelling at anyone, just advising about list mores.)
--
David
>
> 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list