Applying lmer() function across all columns in dataframe. I have made a list of variables and used lapply. Below is the code:
varlist=names(Genus_abundance)[5:ncol(Genus_abundance)]
lapply(varlist, function(x){lmer(substitute(i ~ Status + (1|Match), list(i=as.name(x), data=Genus_abundance, na.action = na.exclude)))})
However, I keep getting this error:
 Error in eval(predvars, data, env) : object 'Acetatifactor' not found
I have checked and Acetatifactor is in the Genus_abundance dataframe.
Bit stuck about where its going wrong
EDIT: Added a working example:
set.seed(43)
n <- 6
dat <- data.frame(id=1:n, Status=rep(LETTERS[1:2], n/2), age= sample(18:90, n, replace=TRUE), match=1:n, Acetatifactor=runif(n), Acutalibacter=runif(n), Adlercreutzia=runif(n))
head(dat)
id Status age match Acetatifactor Acutalibacter Adlercreutzia
1  1      A  49     1     0.1861022     0.1364904     0.8626298
2  2      B  31     2     0.7297301     0.8246794     0.3169752
3  3      A  23     3     0.4118721     0.5923042     0.2592606
4  4      B  64     4     0.4140497     0.7943970     0.7422665
5  5      A  60     5     0.4803101     0.7690324     0.7473611
6  6      B  79     6     0.4274945     0.9180564     0.9179040
 
    