[R] list matching

2007-10-06 Thread Adrian Dusa
Dear list, Given a list of elements like: aa <- list(one=c("o", "n", "e"), tea=c("t", "e", "a"), thre=c("t", "h", "r", "e")) Is there a function that returns the intersection between all? Both match() and intersect() only deal with two arguments, but sometimes I ha

Re: [R] list matching

2007-10-06 Thread Marc Schwartz
On Sat, 2007-10-06 at 19:49 +, Adrian Dusa wrote: > Dear list, > > Given a list of elements like: > aa <- list(one=c("o", "n", "e"), >tea=c("t", "e", "a"), >thre=c("t", "h", "r", "e")) > > Is there a function that returns the intersection between all? > Both ma

Re: [R] list matching

2007-10-06 Thread Adrian Dusa
On Saturday 06 October 2007, Marc Schwartz wrote: > [...] > > intersectList <- function(x) > { > res <- table(unlist(sapply(x, unique))) > names(res[res == length(x)]) > } > > > In the first line, I use unique() to ensure that if the same letter > appears more than once in the same list element

Re: [R] list matching

2007-10-06 Thread Gabor Grothendieck
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 st

Re: [R] list matching

2007-10-06 Thread Adrian Dusa
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 p

Re: [R] list matching

2007-10-07 Thread Gabor Grothendieck
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

Re: [R] list matching

2007-10-07 Thread Adrian Dusa
On Sunday 07 October 2007, you wrote: > Perhaps its a version problem? [...] > > > R.version.string # Vista > > [1] "R version 2.6.0 beta (2007-09-23 r42958)" > > > packageDescription("zoo")$Version > > [1] "1.3-2" I don't know, everything is up to date here, too. I'm using Kubuntu Linux and the

Re: [R] list matching

2007-10-07 Thread Gabor Grothendieck
I thought the latest zoo fixes were on CRAN but perhaps they are not. Try this: library(zoo) # next line loads latest version of merge.zoo (fixed in August) source("http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/R/merge.zoo.R?rev=361&root=zoo";) as.vector(time(do.call(me

Re: [R] list matching

2007-10-07 Thread Adrian Dusa
On Sunday 07 October 2007, Gabor Grothendieck wrote: > I thought the latest zoo fixes were on CRAN but perhaps they > are not. Try this: > > library(zoo) > # next line loads latest version of merge.zoo (fixed in August) > source("http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/

Re: [R] list matching

2007-10-07 Thread Gabor Grothendieck
On 10/7/07, Adrian Dusa <[EMAIL PROTECTED]> wrote: > On Sunday 07 October 2007, Gabor Grothendieck wrote: > > I thought the latest zoo fixes were on CRAN but perhaps they > > are not. Try this: > > > > library(zoo) > > # next line loads latest version of merge.zoo (fixed in August) > > source("ht