Re: [R] Pairwise intersect comparisons of list elements

From: jim holtman <jholtman_at_gmail.com>
Date: Thu, 20 Nov 2008 20:14:15 -0500

yet another way:

> mapply(function(x,y)length(intersect(x,y)), q, w)
[1] 0 1 3 3

On Thu, Nov 20, 2008 at 7:15 PM, Stefan Th. Gries <stgries_at_gmail.com> wrote:
> Hi all
>
> I have two lists that have the same number of numeric vectors such as:
> q<-list(1, 2:3, 4:6, 7:10)
> w<-list(0, 1:2, 3:7, 8:10)
>
> What I want to do is create a vector desired.result that looks like
> this but I am thinking there must be some kind of non-loop /
> "\\wapply" way to so ...
>
> desired.result<-numeric()
> for (i in 1:4) desired.result[i]<-length(intersect(q[[i]], w[[i]]))
> desired.result
>
> Any ideas? Thx,
> STG
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

______________________________________________
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.
Received on Fri 21 Nov 2008 - 01:21:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Nov 2008 - 03:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive