Re: [R] variables in object names

From: Sarah Goslee <>
Date: Tue 12 Sep 2006 - 20:20:49 GMT

Hi Ken,

Not quite the way you're thinking about it, but yes, there is, and it is very useful. See ?get for more information, but here's the basics:

for(i in 2:5) {
  thismodel <- get(paste("model", i, sep=""))   rsq <- c(rsq, summary(thismodel)$r.squared) }

Also see ?assign for the opposite effect.

On 9/12/06, Pierce, Ken <> wrote:
> Is there any way to put an argument into an object name. For example,
> say I have 5 objects, model1, model2, model3, model4 and model5.
> I would like to make a vector of the r.squares from each model by code
> such as this:
> rsq <- summary(model1)$r.squared
> for(i in 2:5){
> rsq <- c(rsq, summary(model%i%)$r.squared)
> }

Sarah Goslee
University Park, PA 16802

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Sep 13 06:25:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 12 Sep 2006 - 20:31:02 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.