s-news
[Top] [All Lists]

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

To: Sarah Henderson <sarah.henderson@ubc.ca>
Subject: Re: A (probably) trivial question about first occurrence in unique()
From: Tim Hesterberg <timh@insightful.com>
Date: 30 May 2007 15:30:06 -0700
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <7.0.1.0.2.20070530141341.0254bc50@ubc.ca> (message from Sarah Henderson on Wed, 30 May 2007 14:19:51 -0700)
References: <7.0.1.0.2.20070530141341.0254bc50@ubc.ca>
Recent versions of S+ have duplicated.data.frame.
So if your data are in a data frame "data", you could pass
that function the data frame with the two columns, and use
that to subscript rows of the original data frame:

data[ !duplicated(data[c("STREETS","MUNIC")]), ]

Tim Hesterberg

>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?


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