Fitting a linear model with multiple LHS
问题 I am new to R and I want to improve the following script with an *apply function (I have read about apply , but I couldn\'t manage to use it). I want to use lm function on multiple independent variables (which are columns in a data frame). I used for (i in (1:3) { assign(paste0(\'lm.\',names(data[i])), lm(formula=formula(i),data=data)) } Formula(i) is defined as formula=function(x) { as.formula ( paste(names(data[x]),\'~\', paste0(names(data[-1:-3]), collapse = \'+\')), env=parent.frame() ) }