[R] list matching

Gabor Grothendieck ggrothendieck at gmail.com
Sun Oct 7 16:33:31 CEST 2007


Perhaps its a version problem?  Here is what I get:

> aa <- list(one=c("o", "n", "e"),
+               tea=c("t", "e", "a"),
+               thre=c("t", "h", "r", "e"))
> library(zoo)
> as.vector(time(do.call(merge, c(lapply(aa, function(x) zoo(,x)), all = FALSE))))
[1] "e"
>
> R.version.string # Vista
[1] "R version 2.6.0 beta (2007-09-23 r42958)"
> packageDescription("zoo")$Version
[1] "1.3-2"



On 10/7/07, Adrian Dusa <dusa.adrian at gmail.com> wrote:
> On Sunday 07 October 2007, Gabor Grothendieck wrote:
> > zoo's merge can do a multiway intersection.  We turn each component
> > of aa into the times of a dataless zoo object (assuming the elements of
> > each component are unique) and merge them together using all = FALSE
> > which will only leave those points at times in all components.  Extracting
> > the time and stripping off the names gives the result.
> >
> > library(zoo)
> > as.vector(time(do.call(merge, c(lapply(aa, function(x) zoo(,x)), all =
> > FALSE))))
>
> Hi Gabor, it's always good to see clever solutions. Never thought about using
> time series to perform intersections :)
>
> I can't reproduce your solution though:
> Error in rval[[1]] : subscript out of bounds
>
> The elements of each component are indeed unique; the argument all = FALSE
> intrigues me: which function should use it, zoo() or c() ?
>
> The result of lapply() is a list; when performing c() over that list, the
> argument all = FALSE does nothing but to add another branch... hmm, I should
> really use more time series...
>
> Adrian
>
>
> --
> Adrian Dusa
> Romanian Social Data Archive
> 1, Schitu Magureanu Bd
> 050025 Bucharest sector 5
> Romania
> Tel./Fax: +40 21 3126618 \
>          +40 21 3120210 / int.101
>



More information about the R-help mailing list