creating and then executing command strings
On Fri, May 15, 2009 at 3:38 PM, Romain Francois
<romain.francois at dbmail.com> wrote:
Hi,
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='') ) )
or
text = paste("avg_",colname, " <- 0;", sep='')
parse(text)
eval(parse(text))
Anyway, thanks a lot - you greatly improved the likelihood of me not
working on the weekend!
Best - P