Re: [R] naive question about using an object as the name of another object

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Fri, 18 May 2007 06:49:28 -0400

On 17/05/2007 10:11 PM, Andrew Yee wrote:
> This is a dumb question, but I'm having trouble finding the answer to this.
>
> I'd like to do the following:
>
> x<-"asdf"
>
> and then have
>
> the object x.y become automatically converted/represented as asdf.y (sort of
> akin to macro variables in SAS where you would do:
> %let x=asdf and do &x..y)
>
> What is the syntax for having x represented as "asdf" in x.y ?

You can use assign( gsub("x", x, "x.y"), x.y ), but this is not a normal thing to do in R programs: R is not SAS. You should investigate using a list and setting a member of it, e.g.

asdf$y <- value

or

f <- function(value) list(y=value)
asdf <- f(value)

depending on what you are trying to do.

Duncan Murdoch



R-help_at_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 Fri 18 May 2007 - 10:54:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 May 2007 - 11:31:20 GMT.

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