[R] Turn character /string as variable/column name in summarize in dplyr

John Kane jrkrideau at inbox.com
Sat Jul 23 00:16:22 CEST 2016


It really might help to have a minimum working example
Have a look at 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
and/or 
http://adv-r.had.co.nz/Reproducibility.html

John Kane
Kingston ON Canada


> -----Original Message-----
> From: chenmenis at hotmail.com
> Sent: Fri, 22 Jul 2016 14:08:45 +0000
> To: r-help at r-project.org
> Subject: [R] Turn character /string as variable/column name in summarize
> in dplyr
> 
> Hi all,
> 
> 
> Trying to turn string in to variable in dplyr , it R interprets it as
> strings rather than column name in the data.
> 
> Any ideas?
> 
> 
> shock5 =paste0(shocksName[5],"fit")
>   print(shock5)
> 
>   x<-group_by(plotdata,grp) %>% summarize(
>     Actuals=sum(weight*response/sum(weight)),
> ...
> ...
>     #
> assign(shocksName[4],sum(weight*as.name(paste(shocksName[4],"fit"))/sum(weight))),
>      assign(shocksName[5],sum(weight*(as.environment(shock5))
> /sum(weight)))
>   )
> 
> 
> Sent from Outlook<http://aka.ms/weboutlook>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



More information about the R-help mailing list