Berwin A Turlach wrote: > G'day David, > > On Tue, 10 Feb 2009 13:23:50 +0100 > David Croll <david.cr...@gmx.ch> wrote: > > >> Well, I knew that attach() only creates a copy of the variables in >> the search path. >> >> What I wanted to ask was how to *retrieve* that copy... >> >> > mat >> id age >> 1 NA NA >> 2 NA NA >> 3 NA NA >> 4 NA NA >> 5 NA NA >> >> > attach(mat) >> >> > id <<- sample(100,5) >> > age <<- rnorm(5,mean=30) >> >> How can I make a new data frame out of the id and age that were >> changed above? >> > > R> new.df <- data.frame(id,age) > > Or, perhaps more automatic: > > R> new.df <- do.call(data.frame, sapply(ls(pos=2), as.name)) > >
or perhaps: new.df <- as.data.frame(mget(names(mat), as.environment(2))) vQ ______________________________________________ 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.