Using a large mapply loop I have generated a list with uneven lengths that I must organize into some readable output. The arguments to my mapply were from a matrix having a dimension that clearly laid out the pattern for my output. As
## an example:
set.seed(123)
x <- matrix(rnorm(100), 10, 10)
w <- matrix(rnorm(100, x), 10, 10)
y <- matrix(rnorm(100, w), 10, 10)
Dat <- data.frame('y'=y,'x'=x,'w'=w)
forms <- outer(
colnames(Dat)[1:10],
c(
colnames(Dat)[11:20],
paste(colnames(Dat)[11:20], colnames(Dat)[21:30], sep='+')
), paste, sep=' ~ '
)
forms <- lapply(forms, as.formula) ## dimension attribute lost here
out <- mapply(lm, forms, data=list(Dat), SIMPLIFY=FALSE)
The expected output would be:
> dim(out)
10 20
> out[5, 3] ## the 45th regression model: 45= (3-1)*20 + 5
Coefficients:
(Intercept) x.5
-0.5648 0.3318