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

From: Duncan Murdoch <>
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


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

depending on what you are trying to do.

Duncan Murdoch mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.