[R] How can i keep only latest entries?

p_connolly at slingshot.co.nz p_connolly at slingshot.co.nz
Fri Jan 18 00:13:42 CET 2013


Quoting Mat <matthias.weber at fnt.de>:

> Hello togehter,
>
> i have a data.frame like this one:
>
>     No. Date                 last change
> 1  1     2012-10-04     change settings
> 2  1     2012-10-20     bug fix
> 3  1     2012-11-05     final
> 4  2     2013-01-15    new task
> 5  2     2013-01-16    Bug fix
> 6  2     2013-01-17    final
>

Calling your data frame, x and assuming the `last change` column is character,

x[x$`last change` == "final",]

will give what you want.  If `last change` is a factor column (likely),


x[as.character(x$`last change`) == "final",]


If you don't have spaces in your column names, you'd avoid using the 
backticks.

HTH



> now i want a new data.frame, who show me only the newest entries according
> to the No.
> The solution look like this one:
>
>    No. Date                last change
> 1  1     2012-11-05   final
> 2  2     2013-01-17   final
>
> can anyone help me?
>
> thanks.
>
> Mat
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-can-i-keep-only-latest-entries-tp4655827.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.



More information about the R-help mailing list