This is a fortune(106) situation (with a little fortune(77) in there as well).

I am unsure what exactly the original poster is wanting to do, but accessing 
the columns of a data frame (or list) by character strings can be done using [[ 
]] rather than $ and should be able to work for this situation (and for data 
frames you can use matrix subscripting to get columns by name).

Try things like:

> tmp <- paste( 'x', 1:3, sep='' )
> Data[ , tmp ]
> for( i in seq(along=tmp) ) Data[[ tmp[i] ]]

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Henrique 
> Dallazuanna
> Sent: Monday, January 07, 2008 10:56 AM
> To: Gregory Gentlemen
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] evaluating a vector of characters
> 
> Try:
> sapply(paste("Data$x", 1:3, sep=""), function(x)eval(parse(text=x)))
> 
> On 07/01/2008, Gregory Gentlemen <[EMAIL PROTECTED]> wrote:
> > Dear R users,
> >
> > I'd like to evaluate a vector of characters. For example, 
> say I have a data frame called Data including the field names 
> x1, x2, x3, and I'd like to a list out of paste("Data$x", 
> 1:3, sep=""). How can I get list to evaluate paste("Data$x", 
> 1:3, sep="") as an R object rather than a string?
> >
> > Thanks in advance for you assistance.
> > Gregory
> >
> >
> > ---------------------------------
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org 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.
> >
> 
> 
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
> 
> ______________________________________________
> R-help@r-project.org 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.
> 

______________________________________________
R-help@r-project.org 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.

Reply via email to