[R] how to feed lme() and lmer() data for a loop

Federico Calboli |eder|co@c@|bo|| @end|ng |rom ku|euven@be
Tue Feb 25 09:33:41 CET 2020

Hi all,

I am struggling with an issue related to lme() and lmer().  lm() can easily take stuff on the fly from different objects and be happy:

lm(data1[,1] ~ data2[,1] + data3[,45] + data4[,39])

works — always.  It also allows me to run nice loops:

for(i in 1:whatever){
lm(data1[,1] ~ data2[,i] + data3[,45] + data4[,39])

(for a useless but clear example where I loop the model over all columns of data2).  This property also allows me to totally ignore ’names’ for the data I am using.  

I am at loss why this is not possible with lme() or lmer().  I can go around this issue by building data frames on the fly, but this is cumbresome, both as code and very likely as performance, especially looping over lots of data having to generate these dummy data frames.

If there is a trick I am missing I’d be grateful if anybody could set me straight.



Federico Calboli
LBEG - Laboratory of Biodiversity and Evolutionary Genomics
Charles Deberiotstraat 32 box 2439
3000 Leuven
+32 16 32 87 67

More information about the R-help mailing list