Displaying 20 results from an estimated 60000 matches similar to: "Writing custom functions for rpart"
2018 Jun 08
4
Subsetting the "ROW"s of an object
> On Jun 8, 2018, at 11:52 AM, Hadley Wickham <h.wickham at gmail.com> wrote:
>
> On Fri, Jun 8, 2018 at 11:38 AM, Berry, Charles <ccberry at ucsd.edu> wrote:
>>
>>
>>> On Jun 8, 2018, at 10:37 AM, Herv? Pag?s <hpages at fredhutch.org> wrote:
>>>
>>> Also the TRUEs cause problems if some dimensions are 0:
>>>
2018 Jun 08
3
Subsetting the "ROW"s of an object
> On Jun 8, 2018, at 10:37 AM, Herv? Pag?s <hpages at fredhutch.org> wrote:
>
> Also the TRUEs cause problems if some dimensions are 0:
>
> > matrix(raw(0), nrow=5, ncol=0)[1:3 , TRUE]
> Error in matrix(raw(0), nrow = 5, ncol = 0)[1:3, TRUE] :
> (subscript) logical subscript too long
OK. But this is easy enough to handle.
>
> H.
>
> On
2018 Jun 08
2
Subsetting the "ROW"s of an object
I suspect this will have suboptimal performance since the TRUEs will
get recycled. (Maybe there is, or could be, ALTREP, support for
recycling)
Hadley
On Fri, Jun 8, 2018 at 10:16 AM, Berry, Charles <ccberry at ucsd.edu> wrote:
>
>
>> On Jun 8, 2018, at 8:45 AM, Hadley Wickham <h.wickham at gmail.com> wrote:
>>
>> Hi all,
>>
>> Is there a better to
2007 Feb 23
2
Functions that write functions in R packages
Dear all,
Another question related to my ggplot package: I have made some
substantial changes to the backend of my package so that plot objects
can now describe themselves much better. A consequence of this is
that a number of convenience functions that previously I wrote by
hand, can now be written automatically. What is the best practice for
creating these functions for bundling in a
2018 May 03
2
length of `...`
On Thu, May 3, 2018 at 9:50 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> On 03/05/2018 11:18 AM, Duncan Murdoch wrote:
>>
>> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
>>>
>>> In R-3.5.0 you can use ...length():
>>> > f <- function(..., n) ...length()
>>> > f(stop("one"),
2018 Jun 08
3
Subsetting the "ROW"s of an object
> On Jun 8, 2018, at 1:49 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
>
> Hmmm, yes, there must be some special case in the C code to avoid
> recycling a length-1 logical vector:
Here is a version that (I think) handles Herve's issue of arrays having one or more 0 dimensions.
subset_ROW <-
function(x,i)
{
dims <- dim(x)
index_list <-
2006 Sep 03
2
lm, weights and ...
> lm2 <- function(...) lm(...)
> lm2(mpg ~ wt, data=mtcars)
Call:
lm(formula = ..1, data = ..2)
Coefficients:
(Intercept) wt
37.285 -5.344
> lm2(mpg ~ wt, weights=cyl, data=mtcars)
Error in eval(expr, envir, enclos) : ..2 used in an incorrect context,
no ... to look in
Can anyone explain why this is happening? (Obviously this is a
manufactured example, but it
2004 Apr 18
2
Error in gam?
I'm having some problems using variable names containing spaces (using
backticks) with gam (mgcv 0.9-6, R 1.8.1). Some toy code to reproduce
my problem is below. Am I doing something wrong, or should I pass this
bug on to Simon Wood? (Or do I need to rename my variables to get rid of
the spaces?)
Thanks,
Hadley
library(mgcv)
test <- data.frame(a = c(1:10), `a b` = c(1:10)^2,
2008 Jul 03
1
cross-validation in rpart
Hello list,
I'm having a problem with custom functions in rpart, and before I tear my
hair out trying to fix it, I want to make sure it's actually a problem. It
seems that, when you write custom functions for rpart (init, split and eval)
then rpart no longer cross-validates the resulting tree to return errors. A
simple test is to use the usersplits.R function to get a simple, custom
2006 Aug 09
2
How to draw the decision boundaries for LDA and Rpart object
Hello useR,
Could you please tell me how to draw the decision boundaries in a scatterplot of the original data for a LDA or Rpart object.
For example:
> library(rpart)
>fit.rpart <- rpart(as.factor(group.id)~., data=data.frame(Data) )
How can I draw the cutting lines on the orignial Data?
Or is there any built in functions that can read the rpart object 'fit.rpart' to do
2005 Aug 26
1
Help in Compliling user -defined functions in Rpart
I have been trying to write my own user defined function in Rpart.I
imitated the anova splitting rule which is given as an example.In the
work I am doing ,I am calculating the concentration index(ci) ,which
is in between -1 and +1.So my deviance is given by
abs(ci)*(1-abs(ci)).Now when I run rpart incorporating this user
defined function i get the following error message:
Error in
2018 May 03
3
length of `...`
Hi,
It would be great if one of the experts could comment on the
difference between Hadley's dotlength and ...length? The fact
that someone bothered to implement a new primitive for that
when there seems to be a very simple and straightforward R-only
solution suggests that there might be some gotchas/pitfalls with
the R-only solution.
Thanks,
H.
On 05/03/2018 08:34 AM, Hadley Wickham
2005 Oct 13
1
Getting ... as an unevaluated list
Hi,
I'm trying to get ...as a list of unevaluated arguments, ie.
substitute(list(...)) gives me an unevaluated list of the arguments,
but I want a list of the unevaluated arguments.
My attempts so far:
(function(...) substitute(...))(a=1, b=a) # Only returns first
(function(...) substitute(list(...)))(a=1, b=a) # Unevaluated list,
not list of unevaluated
(function(...)
2012 Aug 01
1
rpart package: why does predict.rpart require values for "unused" predictors?
After fitting and pruning an rpart model, it is often the case that one or
more of the original predictors is not used by any of the splits of the
final tree. It seems logical, therefore, that values for these "unused"
predictors would not be needed for prediction. But when predict() is called
on such models, all predictors seem to be required. Why is that, and can it
be easily
2007 Dec 16
1
paste dependent variable in formula (rpart)?
Hello,
i'm trying to replace different target variables in rpart with a
function. The data.frame getting always the target variable as last column.
Try below, i get the target variable in the explained variables, too!?
Have anybody an advice to avoid this.
rp1 <- rpart(eval(parse(text=paste(names(train[length(train)])))) ~ . ,
data=train,cp=0.0001)
regards & many thanks
2004 Mar 19
2
How to collect trees grown by rpart
Jonathan,
Try making a list instead of an array. See ?list. Also, did you look into
random forests? I'm not sure what you want to do, but there might be
methods there to do some of the work for you.
Sean
On 3/19/04 1:12 PM, "Jonathan Williams"
<jonathan.williams at pharmacology.oxford.ac.uk> wrote:
> I would like to collect the trees grown by rpart fits in an array,
2015 Oct 31
1
Example input data with example output using relative pathway in vignette of R package?
I'm putting together an R package. I would like to show example code in the
vignette, where example data files (included in the package) are used to
generate an (example) output file.
I read about using example data in Hadley Wickham's post (
http://r-pkgs.had.co.nz/data.html), and believe I should keep my example
data as raw data, as it must be parsed to generate the output.
So, I
2006 May 09
1
Seg fault when installing package from bad repository
> install.packages("rggobi", repos="http://ggobi.org/r/")
Warning in install.packages("rggobi", repos = "http://ggobi.org/r/") :
argument 'lib' is missing: using /Users/hadley/Library/R/library/
Reading symbols for shared libraries . done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at
2004 Sep 01
3
How to personalize the rpart function: t.default(x)
I'm trying to personalize the rpart function by introducing a
list('init','split','eval') in the argument method. But I receive an error
message:"Error in t.default(x): argument is not a matrix".
Can anyone tell me what the argument of this function is or where this
function appears in the rpart function.Thanks Simone Vantini
2024 May 28
2
Segfault when parsing UTF-8 text with srcrefs
Hi all,
When I run the following code, R segfaults:
text <- "?"
srcfile <- srcfilecopy("test.r", text)
parse(textConnection(text), srcfile = srcfile)
It doesn't segfault if text is ASCII, or it's not wrapped in
textConnection, or srcfile isn't set.
Hadley
--
http://hadley.nz
[[alternative HTML version deleted]]