[R] Filter according to the latest data

Gabor Grothendieck ggrothendieck at gmail.com
Sun Feb 3 03:18:28 CET 2013


On Fri, Feb 1, 2013 at 8:05 AM, nalluri pratap <pratap_stat at yahoo.co.in> wrote:
> library(sqldf)
>

> sqldf("select *
> from k1
> group by No
> having max(Date)")
>

HAVING is only used to select groups and only works by chance in this
example but if the data were to change then it would likely not work.

Try this instead.  It makes use of an sqlite-specific feature that
guarantees that when MAX is used in a GROUP BY that the other columns
will be from the same row:

> sqldf("select ID, No, Change, max(Date) Date from k1 group by No")
  ID  No    Change       Date
1  D 111     final 2013-01-12
2  C 123 bug fixed 2013-01-17


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list