Entering edit mode
4.1 years ago
selplat21
▴
20
Hello,
I have a list of linear model outputs in R:
Models <- c('FGm', 'ECm', 'BWm', 'Mm', 'BDm', 'Cm', 'WCm', 'FCm',
'DPC1m','DPC2m','DPC3m','DPC4m','DPC5m','DPC6m','DPC7m',
'DPC8m','DPC9m','DPC10m','SPC1m','SPC2m','SPC3m','SPC4m',
'SPC5m','SPC6m','SPC7m','SPC8m','SPC9m','SPC10m', 'Ipom',
'Mertm', 'Seasm')
I am trying to generate a column with residual and predicted values in the dataframe:
for (i in Models){
res <- paste('Data$', i,".res", sep="")
pred <- paste('Data$', i,".pred", sep="")
res <- residuals(i)
pred <- predict(i)
}
I keep getting the following error, can someone help with this?
Error: $ operator is invalid for atomic vectors
Try:
That is helpful, thank you! The problem here is that the following concatenated list is in character format, but I want each item in this list to be treated as an lm type object. So, not sure how to just get these read in as lm objects.
Beyond that, are you aware that the first
res
andpred
are being overwritten in the 3th and 4th line of the for loop body without seemingly being used before?So here was my rationale here:
Sorry, I realized the overwrite. The following should illustrate what I want to do:
The problem here is that I'm unable to access the names of the list items from above. This term "names(Models)[i]" won't work unfortunately.