r - Check if row of a dataframe is equal to a row of another disregarding NA values -
I have two data.frames.
DF1 can contain multiple rows, which are never used by NAS and it seems like:
col1 col2 col3 col4 1 1 2 1 2 1 2 3 3 1 2 1 1 2 2 2
While df2 is always a line, it can contain NAS and it looks like this:
col1 col2 Col3 col4 1 na 2 na
I'm exploring a way to test for each line DF1 if DF2 is equal to the line that is dissolving all values of NA . After checking for the above example, I hope:
true false false true
So far I have many combinations of all Have tried and which () but I have not found an efficient solution
Thank you.
You can:
m1 < - t (df1) v1 & lt; - unlist (df2) m1 [is.na (v1)] & lt; - NA colsums (m1 == v1 | Is.na (m1)) == ncol (m1) # [1] Correct false false truth
Comments
Post a Comment