[R] creating and then executing command strings
phi.schmidt at gmail.com
Fri May 15 16:35:17 CEST 2009
On Fri, May 15, 2009 at 3:38 PM, Romain Francois
<romain.francois at dbmail.com> wrote:
> You can either parse and eval the string you are making, as in:
> eval( parse( text = paste("avg_",colname, " <- 0;", sep='') ) )
> Or you can do something like this:
> df[[ paste( "avg_", colname, sep = "" ) ]] <- 0
Thanks you so much! I used the first version and it worked.
What puzzles me, is that I am not able to use <- instead of = (my R
book says the two can be exchanged) or break the command into
different parts and execute them one after another.
I get various error messages when I try:
eval( parse( text <- paste("avg_",colname, " <- 0;", sep='') ) )
text = paste("avg_",colname, " <- 0;", sep='')
Anyway, thanks a lot - you greatly improved the likelihood of me not
working on the weekend!
Best - P
More information about the R-help