Skip to content

find difference between data frames

2 messages · psy106616, R. Michael Weylandt

#
I have one data frame, like below?
        kind        x        y
1        1          8         9
2        1        44        3
3        1        25        7
4        1         36       20
5        2         2          14
6        2         36       20

so, I want to find unique coordinates in kind 1 rather than kind 2, ex, row
4 should be excluded, is that possible?

--
View this message in context: http://r.789695.n4.nabble.com/find-difference-between-data-frames-tp4418328p4418328.html
Sent from the R help mailing list archive at Nabble.com.
#
I'm not sure if you mean to ignore row 6 while ignoring row 4 or not
so here are two solutions (depending on what you meant)

dput(x) # dput is your friend
structure(list(kind = c(1L, 1L, 1L, 1L, 2L, 2L), x = c(8L, 44L,
25L, 36L, 2L, 36L), y = c(9L, 3L, 7L, 20L, 14L, 20L)), .Names = c("kind",
"x", "y"), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "6"))

## If you want to get rid of duplicates for both cases -- not the
prettiest but it works
table(x[!(duplicated(x[,-1], fromLast = TRUE) | duplicated(x[,-1])),1])

## If you only want to get rid of it for the kind==1 rows (assuming
the data.frame is sorted by kind)
table(x[!duplicated(x[,-1], fromLast = TRUE), 1])

It's usually good practice to say what the answer you expect is to
avoid this sort of confusion.

Michael
On Fri, Feb 24, 2012 at 2:00 PM, psy106616 <psy106616 at 163.com> wrote: