Re: [R] Rpart and case weights: working with functions

From: Xavier Robin <Xavier.Robin_at_medecine.unige.ch>
Date: Tue, 03 Jun 2008 15:50:44 +0200

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 03 Jun 2008 - 15:39:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jun 2008 - 17:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive