[R] intersection between two matrices based on two columns in R
dwinsemius at comcast.net
Wed Sep 9 21:53:32 CEST 2015
On Sep 9, 2015, at 12:39 PM, Lida Zeighami wrote:
> Hi there,
> I want to find the intersection between two different data frame or
> matrices based on two columns.
> for example in matrix A I have 5 columns, the first two columns are Id1 and
> Id2 and I have the same columns in the other matrix B, (Id1, Id2 ,,,)
> how can I find the intersection between these two matrices based on columns
> Id1 and Id2 in R?
It's not clear to me what you mean by the intersection of matrices, but if you want the intersection of a column vector, A[ ,'Id1'] , with another column vector, B[ , 'Id1'], then this produces the intersection (as a vector):
intersect( A[ ,'Id1'] , B[ , 'Id1'])
I suspect, however that your native language is not R or "database" (and perhaps not English) so my alternate hypothesis is that you really intend to _merge_ these "matrices", which I suspect are really dataframes:
my_inner_join <- merge(A, B, by=c("Id1", "Id2") )
> [[alternative HTML version deleted]]
This is a plain text mailing list.
Alameda, CA, USA
More information about the R-help