Re: [R] How to identify overlapped items from two list and plot them?

From: Ben Tupper <PemaquidRiver_at_tidewater.net>
Date: Sat, 31 May 2008 17:14:40 -0400

Hello,

On May 31, 2008, at 4:10 PM, ss wrote:

> Hi list,
>
> I have a question on how to identify the overlapped items from two
> vectors:
>
>> x<-c(0,1,2)

>> y<-c(1,2,2,3)
>

You can use the %in% operator to return a logical vector that indicates the overlap.

 > x<-c(0,1,2)
 > y<-c(1,2,2,3)
 > y %in% x

[1] TRUE TRUE TRUE FALSE
> and plot the number of the overlapped as well as non-overlapped in a
> diagram?

>

I am not sure what you mean by plotting the number of overlaps. Do you mean show the overlaps with a special symbol? Or do you want to just show the number?

If it is the former, perhaps the following would do?

 > plot(x,rep(1,length(x)), xlim = c(0,5))
 > points(y, rep(1,length(y)), pch = "+")
 > iy = which(y %in% x)
 > points(y[iy], rep(1,length(iy)), pch = "+", col = "red")

Cheers,
Ben
Ben

> Thanks much,
> Allen
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

Ben Tupper
PemaquidRiver_at_tidewater.net

I GoodSearch for Ashwood Waldorf School.

Raise money for your favorite charity or school just by searching the Internet with GoodSearch - www.goodsearch.com - powered by Yahoo!



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 Mon 02 Jun 2008 - 04:24:09 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 Mon 02 Jun 2008 - 04:30:40 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