I am trying to save the summary outputs of a lm
into a data frame, "csv" or "txt" file. What I wanted to do is to use a lm
(and eventually glm
) with different dependent variables, but the same independent variables.
This is my code using lapply
for model fitting:
varlist <- names(NDVI)[2:244]
models <- lapply(varlist, function(x) {
lm(substitute(i ~ efectohuracan, list(i = as.name(x))), data = NDVI)})
If I save it as
write.csv(models,"models.csv")
I get this error
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
stringsAsFactors) : cannot coerce class ""lm"" to a data.frame
I am very new in R. The code I made it thanks to people who has posted their problems also in this community, so maybe there are better ways to approach this.
Thank you in advance