[R] Rpart and case weights: working with functions
Xavier Robin
Xavier.Robin at medecine.unige.ch
Tue Jun 3 15:50:44 CEST 2008
S Ellison a écrit :
> As a work-round, try something lik
>
> test.function <- function (formula.str, data) {
> weights <- rep(.1, 8)
> rpart(as.formula(formula.str), data, weights)
> }
>
> which works if formula.str is a string instead of a formula object.
Ok, I think I got the point. The only problem with transforming the
string to a formula is that rpart raises another error:
> Error in t.default(x) : argument is not a matrix
> test.function <- function (form, data) {
> weights <- rep(.1, 8)
> environment(form)<-environment() #re-sets the formula environment
> rpart(form, data, weights)
> }
This works perfectly well. It will be good enough for what I need.
Thanks a lot ;-)
Xavier
More information about the R-help
mailing list