[R] select unique by multiple values
gunter.berton at gene.com
Wed Oct 9 22:43:39 CEST 2013
On Wed, Oct 9, 2013 at 11:49 AM, Berend Hasselman <bhh at xs4all.nl> wrote:
> On 09-10-2013, at 13:50, Ronald Peterson <ron at hub.yellowbank.com> wrote:
>> New to R here. Lots of fun. Still rather green though.
>> I'd like to select unique items from a list that looks like this (for
>>  8 6 9 0 0 3 9 7 1 9
>>  1 2 9 5 1 2 0 9 2 9
>>  5 6 9 0 5 1 1 7 3 4
>> I'd like to select unique (x,y), while preserving association with z
>> values. When there are duplicate (x,y) pairs, it doesn't really matter
>> which (x,y,z) triplet gets preserved - selecting the first would be fine,
>> but any other way to do it would be fine also. It /would/ be handy to also
>> get a list of the rejected triplets, if that's possible. Ideas?
> You could try this
> A <- cbind(xyz[],xyz[])
> indx <- which(duplicated(A))
> lapply(xyz,function(u) u[-indx])
> lapply(xyz,function(u) u[indx])
indx <- duplicated(A))
Fear not logical indexing!
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
More information about the R-help