Hi folks, I thought I recalled a request for turning a character string into an object name as in: x$as.name("y")<-1:4 OR x<-data.frame(as.name("y")=1:4) However, as.name and a few other uninformed attempts didn't even come close. A search of "character to name" produced no helpful functions. This isn't a very urgent request, but if anyone knows some trick to perform this transformation, I would like to hear about it. Thanks. Jim
Is one of these alternatives what you want? # 1 x <- list() x[["y"]] <- 1:4 x <- as.data.frame(x) x # 2 x <- data.frame(1:4) names(x) <- "y" x # 3 x <- as.data.frame(sapply("y", function(x, y) y, 1:4, simplify = FALSE)) x On 7/9/07, Jim Lemon <jim at bitwrit.com.au> wrote:> Hi folks, > > I thought I recalled a request for turning a character string into an > object name as in: > > x$as.name("y")<-1:4 > > OR > > x<-data.frame(as.name("y")=1:4) > > However, as.name and a few other uninformed attempts didn't even come > close. A search of "character to name" produced no helpful functions. > This isn't a very urgent request, but if anyone knows some trick to > perform this transformation, I would like to hear about it. Thanks. > > Jim > > ______________________________________________ > 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. >
On Mon, 9 Jul 2007, Jim Lemon wrote:> Hi folks, > > I thought I recalled a request for turning a character string into an > object name as in:Yes. It's a FAQ. -thomas> x$as.name("y")<-1:4 > > OR > > x<-data.frame(as.name("y")=1:4) > > However, as.name and a few other uninformed attempts didn't even come > close. A search of "character to name" produced no helpful functions. > This isn't a very urgent request, but if anyone knows some trick to > perform this transformation, I would like to hear about it. Thanks. > > Jim > > ______________________________________________ > 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. >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Jim Lemon wrote:> Hi folks, > > I thought I recalled a request for turning a character string into an > object name as in: > > x$as.name("y")<-1:4> ... Thanks to those who replied to this eminently dumb question. OT: I put this down to the Euthermic Model of Cognitive Efficiency. This model, recently developed in Sydney, Australia, proposes that cognitive efficiency is maximized at the most comfortable ambient temperature for the thinker. Thus after riding home in the cold Sydney rain last night, I was unable to think of the simplest answer: names(x)<-"y" until I had gone to bed and warmed up. Then I awoke in the early morning and thought of Gabor's suggestion: x[["y"]]<-... I felt compelled to arise and publish this amazing theory, that not only explains why the rate of intellectual and technical innovation is greatest in the temperate climes, but more importantly, gives me an excuse for asking the question. Jim