[R] using a variable for a column name in a formula

David Epstein David.Epstein at warwick.ac.uk
Sun Oct 13 23:04:50 CEST 2013

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 mailing list