Thanks!

On Fri, Apr 2, 2010 at 11:35 AM, Erik Iverson <eriki@ccbr.umn.edu> wrote:

> Hello,
>
>
> Sam Albers wrote:
>
>> Hello there,
>>
>> I have a situation where I would like to select the first row of a
>> particular factor for a data frame (data example below). So that is, I
>> would
>> like to select the first entry when the factor1 =A and then the first row
>> when factor1=B etc. I have thousands of entries so I need some general way
>> of doing this. I have a minimal example that should illustrate what I am
>> trying to do. I am using R version 2.9.2, ESS version 5.4 and Ubuntu 9.04.
>>
>> Thanks so much in advance!
>>
>> Sam
>>
>> #Minimal example
>>
>> x <- rnorm(100)
>> y <- rnorm(100)
>> xy <- data.frame(x,y)
>> xy$factor1 <- c("A", "B","C","D")
>> xy$factor2 <- c("a","b")
>> xy <- xy[order(xy$factor1),]  #This simply orders the data to look more
>> like
>> the actual data I am working with
>>
>
> Does
>
> xy[!duplicated(xy$factor1),]
>

This most definitely works. What a beautifully elegant solution. Thanks!

>
> do what you want?
>



-- 
*****************************************************
Sam Albers
Geography Program
University of Northern British Columbia
3333 University Way
Prince George, British Columbia
Canada, V2N 4Z9
phone: 250 960-6777
*****************************************************

	[[alternative HTML version deleted]]

