Andrew Yee
2007-May-18 02:11 UTC
[R] naive question about using an object as the name of another object
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 ? Thanks, Andrew [[alternative HTML version deleted]]
Duncan Murdoch
2007-May-18 10:49 UTC
[R] naive question about using an object as the name of another object
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