[R] Check if row of dataframe is superset of any row in another dataframe.
Neha Aggarwal
@gg@rw@lneh@2000 @ending from gm@il@com
Sat Apr 21 09:27:05 CEST 2018
Hi,
I am looking for a way in which I can check if rows in 1 dataframe are
present in another data frame in a unique way. A row in dataframe should be
super set of any row in another dataframe.
I can write a for loop for it, however, that will be inefficient. So, I am
looking for an efficient way to do this in R.
I have explained it with an example below:
I want to check if a row in dataframe B is:
1) either equal to any row in A or
2) has 1's atleast for the columns where (any) row in B has 1's.
My output/result is a vector of 1(TRUE) or 0(FALSE) of length equal to
number of rows in B. The first row in B is exactly present in A so result
has first bit as 1. Second row in B has matches with 2nd row of dataframe A
(it has an extra 1 in 3rd column,which is ok);so second bit of result is
also 1. Similarly, the 3rd row of B, can match to any row in A, so 3rd bit
in result is also a 1. Next, 4th row in B has 1 for a column where no row
in A has 1, so last bit in result is 0.
Dataframe A
1 0 1 0
1 1 0 0
0 1 1 0
Dataframe B
1 0 1 0
1 1 1 0
1 1 1 1
0 0 0 1
Result<- 1 1 1 0
Thanks for the help,
Neha
[[alternative HTML version deleted]]
More information about the R-help
mailing list