[R] trivial question about nested loops

Berton Gunter gunter.berton at gene.com
Thu Sep 2 19:43:02 CEST 2004




> >sum(paste("d$Y",k,sep="")*exp(-1i*j*d$X)) 
> >but I got 
> >Error in : 
> >        non-numeric argument to binary operator
> 
> It thought you were trying to multiply by the string "d$Y1".  There
> are a number of ways to evaluate a string as if it was code, but you
> don't really need those.
> 
> Duncan Murdoch
> 

(Perhaps unnecessary) translation:

In your expression:

paste("d$Y", k, sep = "") * exp(-(0+1i) * j * d$X) 

the paste part to the left of * is (evaluated as) a character string like
'abc': the exp part to the right is (evaluated as)a numeric quantity. It
makes no sense to the "binary operator" * to multiply two such entities
together.

Duncan's remark means that if you want to somehow translate the character
string into a numeric expression that R can understand and do something
with, there are ways to do it (as this is what the "R Evaluator" must do for
anything that one gives it), but it is not necesary to go to such technical
lengths here.

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 


More information about the R-help mailing list