[R] Filter according to the latest data
jim holtman
jholtman at gmail.com
Fri Feb 1 14:12:38 CET 2013
try this:
> x <- read.table(text = " No. Change Date
+ A 123 final 2013-01-15
+ B 123 error 2013-01-16
+ C 123 'bug fixed' 2013-01-17
+ D 111 final 2013-01-12"
+ , header = TRUE
+ , as.is = TRUE
+ )
> do.call(rbind, lapply(split(x, x$No.), function(.sec){
+ .sec[which(.sec$Date == max(.sec$Date))[1L], ]
+ }))
No. Change Date
111 111 final 2013-01-12
123 123 bug fixed 2013-01-17
On Fri, Feb 1, 2013 at 3:04 AM, Mat <matthias.weber at fnt.de> wrote:
> Hello together,
>
> i have a data.frame, like this one:
> No. Change Date
> A 123 final 2013-01-15
> B 123 error 2013-01-16
> C 123 bug fixed 2013-01-17
> D 111 final 2013-01-12
>
> and now a want a new data.frame which includes only the newest entry for
> each number.
> The solution look like this:
> No. Change Date
> C 123 bug fixed 2013-01-17
> D 111 final 2013-01-12
>
> is there any way to filter my data.frame to the latest data, perhabs "max"?
>
> Thanks.
>
> Mat
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Filter-according-to-the-latest-data-tp4657248.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
More information about the R-help
mailing list