I'm writing my first S3 class and associated methods and I would like to know how to subset my input data set in order to keep only the variables specified in the formula?
data(iris)
f <- Species~Petal.Length + Petal.Width
With model.frame(f,iris)
I get a subset with all the variables in the formula. How to automatically keep only the right hand side variables (in the example Petal.Length
and Petal.Width
)?
model.frame(f,iris)[, -1]
? – Duperyas.formula
here.Species~Petal.Length + Petal.Width
is already a formula. – Foxglove