Re: [R] unquoting

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sun 20 Aug 2006 - 21:24:24 EST

Murray Jorgensen <maj@waikato.ac.nz> writes:

> I would like a function to strip quotes off character strings. I should
> work like this:
>
> > A <- matrix(1:6, nrow = 2, ncol=3)
> > AF <- as.data.frame(A)
> > names(AF) <- c("First","Second","Third")
> > AF
> First Second Third
> 1 1 3 5
> 2 2 4 6
> > names(AF)[2]
> [1] "Second"
> > attach(AF)
> > unquote(names(AF)[2])
> [1] 3 4
>
> Of course what I actually get is
>
> Error: couldn't find function "unquote"
>
> The reason that I want to do this is that I have a frame with a rather
> large number of variables and I would like to loop over the names and
> print out various descriptive summaries of the variable's distribution.
>
> OK, OK, I could just go
>
> > AF[,2]
> [1] 3 4
>
> but once I thought of unquoting I have some sort of inner need to know
> how to do it!

Anything wrong with

AF[,names(AF)[2]]

or

AF[[names(AF)[2]]]

or for that matter

eval(as.name(names(AF)[2]), envir=AF)

??

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun Aug 20 21:32:26 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 20 Aug 2006 - 22:21:36 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.