Fw: [R] eval and as.symbol question

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Oct 18 14:52:34 CEST 2001


"Gary Collins" <gco at eortc.be> writes:


> >
> > You might try something like this instead:
> >
> > apply(df, 2, function(x) sum(is.na(x)))
> >
> >
> >
> > Hope this helps
> >
> > Kaspar
> 
> I want to avoid this. I know how the apply function works. The counting
> missing items was merely an example, there are a number of ways to solve
> that particular problem. My question is how to use as.symbol, eval and paste
> to get the required result as I will use very similar steps.

You should probably reconsider the hint from Kaspar that you might
want a more structured solution. Manipulation of code via text strings
is usually not The Right Way of doing things. 

However, if you must, you need to notice that as.symbol creates a
symbol from *any* textstring

> "]{" <- 5
> eval(as.symbol( "]{"))
[1] 5

However a$b is usually not a single symbol but three, an indexing
expression consisting of a, $, and b. If you want to get that from a
text string you need parse("a$b").

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list