s-news
[Top] [All Lists]

Re: A (probably) trivial question about first occurrence in unique()

To: <s-news@lists.biostat.wustl.edu>, "Sarah Henderson" <sarah.henderson@ubc.ca>
Subject: Re: A (probably) trivial question about first occurrence in unique()
From: "Alejandro Munoz" <MUNOZ@surgery.wisc.edu>
Date: Wed, 30 May 2007 16:36:17 -0500
In-reply-to: <7.0.1.0.2.20070530141341.0254bc50@ubc.ca>
References: <7.0.1.0.2.20070530141341.0254bc50@ubc.ca>
Sarah,

This is simple if your data set is sorted by street (tested in R):

# toy example
dd <- data.frame(streets=sample(letters[1:10], 100, repl=TRUE), 
                  munic=sample(LETTERS[1:3], 100, repl=TRUE))
dd <- dd[order(dd$streets),]    # sort alpha by streets
dd2 <- dd[match(unique(dd$streets), dd$streets),]

HTH,

Alejandro

On 5/30/2007 at 4:19 PM, Sarah Henderson <sarah.henderson@ubc.ca> wrote:

> Hello to all --
> 
> I have data for 300000 road segments reflecting approximately 60000 
> unique street names.  I would like to create a new data frame with 
> the unique street names and their first-occurrence municipalities 
> (they are sorted North to South).  Of course unique(STREETS) gives me 
> the first part, but is there some way to get the MUNIC of the first 
> occurrence without writing a loop?
> 
> Many thanks,
> 
> Sarah
> 
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news


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