0

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 
AdamO
  • 4,283
  • 1
  • 27
  • 39
  • 2
    Suggested duplicate: [How to create a matrix of lists in R?](https://stackoverflow.com/q/30007890/903061). – Gregor Thomas Dec 28 '17 at 16:50
  • In short, lists don't have dimensions, but you can make a matrix where each entry is a list. I'm not quite sure what you expect - you posting doesn't contain a question or expected output. – Gregor Thomas Dec 28 '17 at 16:52
  • @Gregor sorry I edited to post expected output, and I agree with the suggested duplicate. – AdamO Dec 28 '17 at 17:04

0 Answers0