Dear R list,

I have a problem in assigning values to existing data frames in R. I have a
vector x containing the names of the data frames, which I create to store
the results for each variable (a1,a2,a3) obtained in time series moving
regressions. Thus, say,

x=c('a1','a2','a3')

Moreover, b is a vector containig unique dates of the points in time of the
moving regressions. Thus, say,

b=c('2012-11-30','2012-12-31')

I create the data matrices in the following way:

  for (i in 1:(length(x))){
        assign(
                paste(x[i]),
                        matrix(NA,ncol=5,nrow=length(b),
                                dimnames=list(paste(b), 
c('Estimate','Std.Error','t value','p
value','R-squared'))))
  }     


After doing so, I want to store the results of the regressions in the
following way:

  for (i in 1:length(x)){
        for (j in 1:length(b)){
                get(x[i])[j,1]<-summary(get(paste(b[j])))$coefficients[i,1]
                get(x[i])[j,2]<-summary(get(paste(b[j])))$coefficients[i,2]
                get(x[i])[j,3]<-summary(get(paste(b[j])))$coefficients[i,3]
                get(x[i])[j,4]<-summary(get(paste(b[j])))$coefficients[i,4]
                get(x[i])[j,5]<-summary(get(paste(b[j])))$r.squared
    }
  }

However, R produces an error. The reason is that it seems that using
the get() function on the left hand side in the above expressions is
inappropriate in the for loop.

Does anybody have an idea?

Thank you very much in advance.

Regards

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to