Skip to content
Prev 198102 / 398500 Next

Using a variable in the formula

On 27/10/2009, at 4:26 PM, jmark17 wrote:

            
No you don't.  You *might* want to put list[[1]] --- learn
	the difference between [[]] and [] for lists, i.e. RTFM, in
	particular ?"[" --- but it still wouldn't work.
(a) Don't call your list ``list''.  (Cf. fortune("dog").)

(b) You really want a character *vector* not a list.  E.g.

	nms <- c("X1", "X2", "X3")

(c) Execute

	fmla <- as.formula(paste(nms[1],"~ elevation + slope + vegtype"))
	mxl  <- randomForest(fmla,data=moths.train)

Have tested the construction of ``fmla'' --- that works.  I don't know
from randomForest(), so I haven't tested that bit.

HTH.

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}