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
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
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
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
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
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)
}
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
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))
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
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 -
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
; 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
12 matches
Mail list logo