I am trying to use lme function from nlme package inside a for loop. I have tried (almost) everything now, but without any luck. Without the loop my lme function are working
Without knowing your data, conceptually it should be sth like that
df <- data.frame(lipid = rep(c(LETTERS[1:4]), each = 4), x1 = c(rnorm(16, 10, 1)), x2 = c(rnorm(16, 20, 5) ))
df
for (i in levels(df$lipid)){
print(paste("MODEL", i, sep = ""))
df1 = subset(df, lipid == i)
model <- lm(x1~x2, data = df1 )
print(summary(model)$coef)
}