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

Chen Meng chenmenis at hotmail.com
Fri Jul 22 16:08:45 CEST 2016


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]]



More information about the R-help mailing list