Apologies for such an elementary question - I have to miss something obvious.
I want to create a list of objects lmthat I will then use in a call llplyto perform mediation analysis on this list. But this is not essential - first I want to make a list of length m (where m is the set of models), and each element in m itself will contain n lmobjects.
So in this simple example
d1 <- data.frame(x1 = runif(100, 0, 1),
x2 = runif(100, 0, 1),
x3 = runif(100, 0, 1),
y1 = runif(100, 0, 1),
y2 = runif(100, 0, 1),
y3 = runif(100, 0, 1))
m1 <- lm(y1 ~ x1 + x2 + x3, data = d1)
m2 <- lm(x1 ~ x2 + x3, data = d1)
m3 <- lm(y2 ~ x1 + x2 + x3, data = d1)
m4 <- lm(x2 ~ x1 + x3, data = d1)
m5 <- lm(y3 ~ y1 + y2 + x3, data = d1)
m6 <- lm(x3 ~ x1 + x2, data = d1)
I wish list comprising 3 elements and the first element will contain m1and m2the second will contain m3and m4etc. My initial attempt is correct, but lmm objects do not retain their class.
mlist <- list(c(m1,m2),
c(m3,m4),
c(m5,m6))
(.. length(mlist) 3), , lm
class(mlist[1][[1]])
, -, .
, , - lm?