[R] removing duplicate rows

0 views
Skip to first unread message

Jim Bouldin

unread,
May 11, 2010, 8:07:30 PM5/11/10
to R help

I'm trying to identify and remove rows in a data frame that are duplicated
only on particular columns within it (i.e. not on all columns). The
"unique" function looks for uniqueness across all columns of a data frame.
Identifying unique rows based only on specific columns of interest returns
only those columns, not all of the columns in the original frame. I tried
this, and then added an identifier column to this truncated data frame, and
then tried merging this with the original data frame and selecting only
those rows container the identifier. But this did not work no matter how
the arguments were altered: all records were returned instead of the
uniques. Completely stumped--any help appreciated. Thanks.



Jim Bouldin, PhD
Research Ecologist
Department of Plant Sciences, UC Davis
Davis CA, 95616
530-554-1740

______________________________________________
R-h...@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.

--
You received this message because you are subscribed to the Google Groups "R-help-archive" group.
To post to this group, send email to r-help-...@googlegroups.com.
To unsubscribe from this group, send email to r-help-archiv...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/r-help-archive?hl=en.

Sean Anderson

unread,
May 11, 2010, 8:28:48 PM5/11/10
to R help
On Tue, May 11, 2010 at 9:07 PM, Jim Bouldin <jrbo...@ucdavis.edu> wrote:
>
> I'm trying to identify and remove rows in a data frame that are duplicated
> only on particular columns within it (i.e. not on all columns).

This is probably the cleanest way:

dat <- data.frame(x = c(1, 2, 3), y = c(1, 1, 3))
subset(dat, !duplicated(y))

See this thread (among others) for some other options:
http://finzi.psych.upenn.edu/Rhelp10/2010-January/224658.html
Reply all
Reply to author
Forward
0 new messages