There are a number of functions that are dispatched to from split().> methods('split')[1] split.data.frame split.Date split.default split.POSIXct Is there a way to figure out which of these variants is actually dispatched to when I call split? I know that if the argument is of the type data.frame, split.data.frame will be called? Is it the case that if the argument is not of type data.frame, Date or POSIXct, split.default will be called?
Karl Ove Hufthammer
2009-Dec-10 09:46 UTC
[R] How to figure out which the version of split is used?
On Wed, 9 Dec 2009 19:20:47 -0600 Peng Yu <pengyu.ut at gmail.com> wrote:> Is there a way to figure out which of these variants is actually > dispatched to when I call split? I know that if the argument is of the > type data.frame, split.data.frame will be called? Is it the case that > if the argument is not of type data.frame, Date or POSIXct, > split.default will be called?Yes. See ?UseMethod -- Karl Ove Hufthammer
Patrick Connolly
2009-Dec-10 09:48 UTC
[R] How to figure out which the version of split is used?
On Wed, 09-Dec-2009 at 07:20PM -0600, Peng Yu wrote: |> There are a number of functions that are dispatched to from split(). |> |> > methods('split') |> [1] split.data.frame split.Date split.default split.POSIXct |> |> Is there a way to figure out which of these variants is actually |> dispatched to when I call split? I know that if the argument is of the |> type data.frame, split.data.frame will be called? Is it the case that In R-speak, "class" would be a better word than "type". |> if the argument is not of type data.frame, Date or POSIXct, |> split.default will be called? I think it's slightly more complicated than that, but you're more or less on the right track. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
William Dunlap
2009-Dec-11 17:17 UTC
[R] How to figure out which the version of split is used?
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Karl Ove Hufthammer > Sent: Thursday, December 10, 2009 1:46 AM > To: r-help at stat.math.ethz.ch > Subject: Re: [R] How to figure out which the version of split is used? > > On Wed, 9 Dec 2009 19:20:47 -0600 Peng Yu <pengyu.ut at gmail.com> wrote: > > Is there a way to figure out which of these variants is actually > > dispatched to when I call split? I know that if the > argument is of the > > type data.frame, split.data.frame will be called? Is it the > case that > > if the argument is not of type data.frame, Date or POSIXct, > > split.default will be called? > > Yes. See ?UseMethodYou can also use trace() to see what actually happens in test cases. E.g., > invisible(lapply(methods("split"), function(method)trace(method, bquote(cat("Entering", .(method), "x=", class(x), "f=", class(f), "\n"))))) Tracing function "split.data.frame" in package "base" Tracing function "split.Date" in package "base" Tracing function "split.default" in package "base" Tracing function "split.POSIXct" in package "base" > split(data.frame(x=1:3,y=1:3), f=c(10,10,20)) Tracing split.data.frame(data.frame(x = 1:3, y = 1:3), f = c(10, 10, .... on entry Entering split.data.frame x= data.frame f= numeric Tracing split.default(seq_len(nrow(x)), f, drop = drop, ...) on entry Entering split.default x= integer f= numeric $`10` x y 1 1 1 2 2 2 $`20` x y 3 3 3 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> > -- > Karl Ove Hufthammer > > ______________________________________________ > 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. >
Seemingly Similar Threads
- Is there a function to test if all the elements in a vector are unique
- Weird error: Error in xj[i] : invalid subscript type 'list'
- Possible bug in plot.POSIXct regarding x axis
- Subset of time observations where timediff > 60 secs
- Example scripts for R Manual