Maybe is something trivial but I am trying to solve this problem:
I have to data frames, one with 25 and another with 9 columns. Now, what I need to do is to fit polynomial equations where my dependent variable is in the data frame with 25 columns and my independent variable is in the data frame with 9 columns. At the moment I combined the columns together and created a data frame called "my.data", so I am looping over the dependent variables using one independent variable at the time. But, I would like do the functions in the loop 25 * 9 times automatically. Is there any way to do that?
setwd("C:\\......")
my.data <- read.table("MyData.txt", header = TRUE, sep = "\t")
for(i in seq_along(my.data))
{
fit1b <- lm(my.data[ ,i] ~ my.data$V1)
fit2b <- lm(my.data[ ,i] ~ poly(my.data$V1, 2, raw=TRUE))
fit3b <- lm(my.data[ ,i] ~ poly(my.data$V1, 3, raw=TRUE))
poly1 <-capture.output(summary(fit1b))
poly2 <-capture.output(summary(fit2b))
poly3 <-capture.output(summary(fit3b))
con = file(description = "MyResults.txt", open="a")
write.table(poly1, file= con, append = TRUE, quote=F, col.names=FALSE, row.names= F)
write.table(poly2, file= con, append = TRUE, quote=F, col.names=FALSE, row.names= F)
write.table(poly3, file= con, append = TRUE, quote=F, col.names=FALSE, row.names= F)
close(con)
}