[R] Removing rows w/ smaller value from data frame
arun
smartpink111 at yahoo.com
Thu May 23 16:39:38 CEST 2013
Hi,
Try:
datNew<- read.table(text="
activity max_dt
A 2013-03-05
B 2013-03-28
A 2013-03-28
C 2013-03-28
B 2013-03-01
",sep="",header=TRUE,stringsAsFactors=FALSE)
datNew$max_dt<- as.Date(datNew$max_dt)
aggregate(max_dt~activity,data=datNew,max)
# activity max_dt
#1 A 2013-03-28
#2 B 2013-03-28
#3 C 2013-03-28
#or
library(plyr)
ddply(datNew,.(activity),summarize, max_dt=max(max_dt))
# activity max_dt
#1 A 2013-03-28
#2 B 2013-03-28
#3 C 2013-03-28
#or
ddply(datNew,.(activity),summarize, max_dt=tail(sort(max_dt),1))
# activity max_dt
#1 A 2013-03-28
#2 B 2013-03-28
#3 C 2013-03-28
A.K.
----- Original Message -----
From: ramoss <ramine.mossadegh at finra.org>
To: r-help at r-project.org
Cc:
Sent: Thursday, May 23, 2013 10:23 AM
Subject: [R] Removing rows w/ smaller value from data frame
Hello,
I have a column called max_date in my data frame and I only want to keep the
bigger values for the same activity. How can I do that?
data frame:
activity max_dt
A 2013-03-05
B 2013-03-28
A 2013-03-28
C 2013-03-28
B 2013-03-01
Thank you for your help
--
View this message in context: http://r.789695.n4.nabble.com/Removing-rows-w-smaller-value-from-data-frame-tp4667816.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