[R] Issue with %in% - not matching identical rows in data frames

Kaushik Krishnan kaushik.s.krishnan at gmail.com
Tue Nov 3 16:53:05 CET 2009


Hi folks

I have two data frames.  I know that the nth (let's say the 7th) row
in the first data frame (sequence) is there in the second
(today.sequence).  When I try to check that by doing 'sequence[7,]
%in% today.sequence', I get all FALSE when it should be all TRUE.

I'm certain I'm making some trivial mistake.  Any solutions?

The code to recreate the data frames and see for yourself is:
----
sequence <- structure(list(DATE = structure(c(14549, 14549, 14553, 14550,
14557, 14550, 14551, 14550), class = "Date"), DATASET = c(1L,
2L, 1L, 2L, 2L, 3L, 3L, 4L), REP = c(1L, 0L, 2L, 2L, 3L, 0L,
1L, 0L), WRONGS_ABS = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), WRONGS_RATIO = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L), DONE = c(1L, 1L, 0L, 1L, 0L, 1L,
0L, 0L)), .Names = c("DATE", "DATASET", "REP", "WRONGS_ABS",
"WRONGS_RATIO", "DONE"), class = "data.frame", row.names = c(NA,
-8L))

today.sequence <- structure(list(DATE = structure(c(14551, 14550),
class = "Date"),
    DATASET = 3:4, REP = c(1L, 0L), WRONGS_ABS = c(0L, 0L),
WRONGS_RATIO = c(0L,
    0L), DONE = c(0L, 0L)), .Names = c("DATE", "DATASET", "REP",
"WRONGS_ABS", "WRONGS_RATIO", "DONE"), row.names = 7:8, class = "data.frame")

sequence[7,] #You should see '2009-11-03       3   1          0
    0    0'

today.sequence #You can clearly see that sequence [7,] is the first
row in today.sequence

sequence[7,] %in% today.sequence #This should show 'TRUE TRUE TRUE
TRUE TRUE TRUE'.  Instead
# it shows 'FALSE FALSE FALSE FALSE FALSE FALSE'
----

Thanks

-- 
Kaushik Krishnan
(kaushik.s.krishnan at gmail.com)




More information about the R-help mailing list