Dear Simon,

Try this:

# Index -- FALSE, TRUE
sapply(1:nrow(a),function(x) all(a[x,]%in%b))

#  Rows of a that are in b
which(sapply(1:nrow(a),function(x) all(a[x,]%in%b)))

# Reporting
a[sapply(1:nrow(a),function(x) all(a[x,]%in%b)),]


HTH,

Jorge


On Tue, Dec 9, 2008 at 9:57 AM, ppaarrkk <[EMAIL PROTECTED]> wrote:

>
> I want to compare two matrices or data frames and select or get an index
> for
> those rows which are the same in both. I have tried the following :
>
>
>
>
>
>
> a = matrix ( 1:10, ncol = 2 )
> a
>
> b = matrix ( c ( 2,3,4,7,8,9 ), ncol = 2 )
> b
>
> a[a==b]
>
>
>
>
>
>
> a = as.data.frame ( matrix ( 1:10, ncol = 2 ) )
> a
>
> b = as.data.frame ( matrix ( c ( 2,3,4,7,8,9 ), ncol = 2 ) )
> b
>
> a[a==b]
>
>
>
>
>
>
>
>
> Any ideas please.
>
>
> Thanks.
>
>
> Simon Parker
> Imperial College
>
> --
> View this message in context:
> http://www.nabble.com/Selecting-rows-that-are-the-same-in-separate-data-frames-tp20916243p20916243.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to