[R] find difference between data frames
R. Michael Weylandt
michael.weylandt at gmail.com
Sat Feb 25 01:19:32 CET 2012
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:
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list