Re: [R] Aggregate by First case

From: Moshe Olshansky <m_olshansky_at_yahoo.com>
Date: Fri, 30 May 2008 00:32:39 -0700 (PDT)


If df is your dataframe, try

aggregate(df$Year,list(df$Id),min)

> From: Jojje Andersson <dietaamigo_at_hotmail.com>
> Subject: [R] Aggregate by First case
> To: "r-help_at_r-project.org" <r-help_at_r-project.org>
> Received: Friday, 30 May, 2008, 5:13 PM
> Hello!
>
> I have an maybe a to a simple question but I cant get it
> right.
>
> I have a dataframe with in one column an id-variable and in
> another a year-variable. One id-number can occur several
> years.
> I have sorted the dataframe on id then on year so the same
> id-number is sorted by year with the first occurens at top.
>
> Now I want to make a subset of this dataframe with just the
> first year the id-number occur, so the first case of every
> id.
>
> Id Year
> 123456 2001
> 123456 2002
> 123456 2003
> 655432 2001
> 655432 2002
> 655432 2003
>
> Is there a simple command I can do?
>
> Thanks!
>
> Jojje
>
>
> _________________________________________________________________
> [[elided Hotmail spam]]
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 30 May 2008 - 07:36:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 30 May 2008 - 08:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive