[R] using a variable for a column name in a formula
sarah.goslee at gmail.com
Sun Oct 13 23:40:09 CEST 2013
This being R, there are likely other ways, but I use:
lm(as.formula(paste(nnn, "~ .")),data=X)
On Sun, Oct 13, 2013 at 5:04 PM, David Epstein
<David.Epstein at warwick.ac.uk> wrote:
> lm(height ~ ., data=X)
> works fine.
> nnn <- "height" ; lm(nnn ~ . ,data=X)
> How do I write such a formula, which depends on the value of a string variable like nnn above?
> A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns.
More information about the R-help