s-news
[Top] [All Lists]

Re: unique subsetting

To: "Michael Slattery" <Michael.Slattery@epa.state.oh.us>, <s-news@lists.biostat.wustl.edu>
Subject: Re: unique subsetting
From: "Stewart, William" <william.stewart@rbc.com>
Date: Thu, 11 Oct 2007 08:19:20 -0400
In-reply-to: <470CB8ED.C718.0085.0@epa.state.oh.us>
References: <470CB8ED.C718.0085.0@epa.state.oh.us>
Thread-index: AcgLx3wQjq6ES78HR7Oj/ERmS4VeVwAOQsEg
Thread-topic: [S] unique subsetting
Good morning Michael,

Unless I am missing something from your description, I think unique
should work and give you the result you're after.
 

> # generate temp data for testing
> temp.df <- data.frame(a=rep(c("one", "two", "three", "four"),30),
b=rep(1:3,40))
> temp.df[1:15,]
       a b 
 1   one 1
 2   two 2
 3 three 3
 4  four 1
 5   one 2
 6   two 3
 7 three 1
 8  four 2
 9   one 3
10   two 1
11 three 2
12  four 3
13   one 1
14   two 2
15 three 3

> temp.ans <- unique(temp.df)
> temp.ans
       a b 
 1   one 1
 2   two 2
 3 three 3
 4  four 1
 5   one 2
 6   two 3
 7 three 1
 8  four 2
 9   one 3
10   two 1
11 three 2
12  four 3

> # sort to make result easier to read
> temp.ans[order(temp.ans$a, temp.ans$b),]
       a b 
 4  four 1
 8  four 2
12  four 3
 1   one 1
 5   one 2
 9   one 3
 7 three 1
11 three 2
 3 three 3
10   two 1
 2   two 2
 6   two 3
> 


------------------------------------- 
William A. Stewart 
Senior Manager, Operational Risk 
RBC Financial Group 
william.stewart@rbc.com 
phone: 416-974-3019 


-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Michael
Slattery
Sent: 2007, October, 10 11:35 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] unique subsetting

Hello all,
I'm sure this is simple, but is has me stumped this morning...
I have a dataframe with 10K+ repeating names (character) each with an
unique associated ID number. I need to simply extract a list of unique
instances of these pairs. I can easily grab the unique vector of either
one, but cannot think of how to get the other (conditional on uniqueness
of the first). 
Hope that is clear enough.

Thanks!



Michael W. Slattery
Geologist, Ohio EPA
50 West Town Street, Suite 700
Columbus OH, 43215
michael.slattery@epa.state.oh.us
614-728-1221 (Ph)
614-644-2909 (Fax)
_______________________________________________________________________

This e-mail may be privileged and/or confidential, and the sender does not 
waive any related rights and obligations.
Any distribution, use or copying of this e-mail or the information it contains 
by other than an intended recipient is unauthorized.
If you received this e-mail in error, please advise me (by return e-mail or 
otherwise) immediately.  

Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce 
pas aux droits et obligations qui s'y rapportent.
Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il 
contient par une personne autre que le (les) destinataire(s) désigné(s) est 
interdite.
Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser 
immédiatement, par retour de courrier électronique ou par un autre moyen.

<Prev in Thread] Current Thread [Next in Thread>