[R] intersect more than two sets

2007-04-24 Thread Weiwei Shi
Hi, I searched the archives and did not find a good solution to that. assume I have 10 sets and I want to have the common character elements of them. how could i do that? -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. Did you always know? No, I did not. But I believed... ---Matrix III

Re: [R] intersect more than two sets

2007-04-24 Thread Weiwei Shi
assume t2 is a list of size 11 and each element is a vector of characters. the following codes can get what I wanted but I assume there might be a one-line code for that: t3 - t2[[1]] for ( i in 2:11){ t3 - intersect(t2[[i]], t3) } or there is no such apply? On 4/24/07, Weiwei Shi

Re: [R] intersect more than two sets

2007-04-24 Thread Charles C. Berry
On Tue, 24 Apr 2007, Weiwei Shi wrote: Hi, I searched the archives and did not find a good solution to that. assume I have 10 sets and I want to have the common character elements of them. how could i do that? list.of.sets - lapply(1:10,function(x) sample(letters,20)) # for example

Re: [R] intersect more than two sets

2007-04-24 Thread John Fox
4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weiwei Shi Sent: Tuesday, April 24, 2007 2:59 PM To: R Help Subject: Re: [R] intersect more than two sets

Re: [R] intersect more than two sets

2007-04-24 Thread Tony Plate
I don't think there's that sort of apply-reduce function in R, but for this problem, the last line below happens to be a one-liner: set.seed(1) x - lapply(1:10, function(i) sample(letters, 20)) table(unlist(x)) a b c d e f g h i j k l m n o p q r s t u v w x y

Re: [R] intersect more than two sets

2007-04-24 Thread hadley wickham
On 4/24/07, Weiwei Shi [EMAIL PROTECTED] wrote: assume t2 is a list of size 11 and each element is a vector of characters. the following codes can get what I wanted but I assume there might be a one-line code for that: t3 - t2[[1]] for ( i in 2:11){ t3 - intersect(t2[[i]], t3) }

Re: [R] intersect more than two sets

2007-04-24 Thread Weiwei Shi
I had a similar solution by using frequency but having more codes :( I also like the recursive idea : I initially tried to use rapply, however, which can only take one-arg function. thanks, everyone. -w On 4/24/07, hadley wickham [EMAIL PROTECTED] wrote: On 4/24/07, Tony Plate [EMAIL

Re: [R] intersect more than two sets

2007-04-24 Thread hadley wickham
On 4/24/07, Tony Plate [EMAIL PROTECTED] wrote: I don't think there's that sort of apply-reduce function in R, but for this problem, the last line below happens to be a one-liner: Only if you have character data though: x - lapply(1:10, function(i) sample(20, 15))

Re: [R] intersect more than two sets

2007-04-24 Thread Dimitris Rizopoulos
you could try something like the following: t2 - lapply(1:11, function(i) c(a, sample(letters[1:5], sample(10, 1), TRUE), b)) unq.vals - unique(unlist(t2)) ind - rowSums(sapply(t2, %in%, x = unq.vals)) == length(t2) unq.vals[ind] I hope it helps. Best, Dimitris Dimitris

Re: [R] intersect more than two sets

2007-04-24 Thread Peter Dalgaard
hadley wickham wrote: On 4/24/07, Weiwei Shi [EMAIL PROTECTED] wrote: assume t2 is a list of size 11 and each element is a vector of characters. the following codes can get what I wanted but I assume there might be a one-line code for that: t3 - t2[[1]] for ( i in 2:11){ t3 -

Re: [R] intersect more than two sets

2007-04-24 Thread Ron Michael
have u seen ?merge ? - Original Message From: Weiwei Shi [EMAIL PROTECTED] To: R Help R-help@stat.math.ethz.ch Sent: Tuesday, April 24, 2007 10:55:51 PM Subject: [R] intersect more than two sets Hi, I searched the archives and did not find a good solution to that. assume I have 10

Re: [R] intersect more than two sets

2007-04-24 Thread John Fox
; Weiwei Shi Subject: Re: [R] intersect more than two sets hadley wickham wrote: On 4/24/07, Weiwei Shi [EMAIL PROTECTED] wrote: assume t2 is a list of size 11 and each element is a vector of characters. the following codes can get what I wanted but I assume there might be a one