[R] Getting indeices of intersecting elements.

David Winsemius dwinsemius at comcast.net
Wed Oct 14 18:35:20 CEST 2009


On Oct 14, 2009, at 12:15 PM, Praveen Surendran wrote:

> Hi,
>
>
>
> Is there a command to get the indices of intersecting elements of two
> vectors as intersect() will give the elements and not its indices.

?which
>

samp1 <- sample(seq(3,198, by=3), 20); samp2 <- sample(seq(3,198,  
by=3), 20)
  int <- intersect(samp1, samp2)
  int
#[1]  48  87   9 159  36   6  39 105
  which(seq(3,198, by=3) %in% int)
#[1]  2  3 12 13 16 29 35 53

>
>
>
> Thanks in advance.
>
>
>
> Praveen Surendran
>
> School of Medicine and Medical Sciences
>
> University College Dublin
>
> Belfield, Dublin 4
>
> Ireland.
>
>
> 	[[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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list