[R] Unique subsetting question

Ista Zahn izahn at psych.rochester.edu
Wed Sep 22 20:07:34 CEST 2010


Hi Andrew,
You can use duplicated() to index the rows you wish to keep, like this:


test.dat <- data.frame(a=c(1,1:5,5:10), b=1:12, c=letters[1:12]) #make up data

duplicated(test.dat$a) # see what duplicated() function does
!duplicated(test.dat$a) # see how we can invert using the ! function
so that we get non-duplicated

test.dat[!duplicated(test.dat$a),] # this is the important bit: use
indexing to select non-duplicated rows.


Best,
Ista

On Wed, Sep 22, 2010 at 12:35 PM, AndrewPage <savejarvis at yahoo.com> wrote:
>
> I understand how duplicated and unique work for a list where all parts of a
> given row are duplicated, or how to find duplicated values if I'm just
> looking at that first column, but in this case  the rows for 1954 and 1955
> are not completely the same; only quarter 1 is duplicated, so I'm not sure
> how to apply either duplicated or unique in that case.
>
> Thanks,
> Andrew
> --
> View this message in context: http://r.789695.n4.nabble.com/Unique-subsetting-question-tp2550453p2550651.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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list