Re: [R] How to extract last value in each group

2013-08-15 Thread arun
lou To: arun Cc: R help Sent: Thursday, August 15, 2013 11:28 PM Subject: Re: [R] How to extract last value in each group Hi, On Thu, Aug 15, 2013 at 4:03 PM, arun wrote: > HI Steve, > > Thanks for testing. > > When I run a slightly bigger dataset: > set.seed(1254) > name

Re: [R] How to extract last value in each group

2013-08-15 Thread Steve Lianoglou
Hi, On Thu, Aug 15, 2013 at 4:03 PM, arun wrote: > HI Steve, > > Thanks for testing. > > When I run a slightly bigger dataset: > set.seed(1254) > name<- sample(letters,1e7,replace=TRUE) > number<- sample(1:10,1e7,replace=TRUE) > > datTest<- data.frame(name,number,stringsAsFactors=FALSE) > library

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
lt;- as.data.frame(res) system.time(res1<-dat2[c(diff(as.numeric(as.factor(dat2$Date))),1)>0,])  row.names(resNew)<- row.names(res1)  attr(resNew,"row.names")<- attr(res1,"row.names")  identical(resNew,res1) #[1] TRUE A.K. ----- Original Message - From: Steve

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
]  names(res1)<-names(res3New)  identical(res1,as.data.frame(res3New)) #[1] TRUE A.K. - Original Message - From: Steve Lianoglou To: arun Cc: R help Sent: Thursday, August 15, 2013 4:48 PM Subject: Re: [R] How to extract last value in each group Hi, On Thu, Aug 15, 2013 at 1:38 PM, a

Re: [R] How to extract last value in each group

2013-08-15 Thread Steve Lianoglou
Hi, On Thu, Aug 15, 2013 at 1:38 PM, arun wrote: > I tried it again on a fresh start using the data.table alone: > Now. > > dt1 <- data.table(dat2, key=c('Date', 'Time')) > system.time(ans <- dt1[, .SD[.N], by='Date']) > # user system elapsed > # 40.908 0.000 40.981 > #Then tried: > syste

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
5, 2013 3:52 PM Subject: Re: [R] How to extract last value in each group Hi, Looks like you have some free time on your hands :-) Something looks a bit off here, though, I was surprised to see the time you reported for the data.table option: > #separate the data.table creation step: >

Re: [R] How to extract last value in each group

2013-08-15 Thread Steve Lianoglou
Hi, Looks like you have some free time on your hands :-) Something looks a bit off here, though, I was surprised to see the time you reported for the data.table option: > #separate the data.table creation step: > dt1 <- data.table(dat2, key=c('Date', 'Time')) > system.time(ans <- dt1[, .SD[.N],

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
dat2, key=c('Date', 'Time')) system.time(ans <- dt1[, .SD[.N], by='Date']) # user  system elapsed # 38.500   0.000  38.566 ans1<- as.data.frame(ans) row.names(ans1)<- row.names(res1) attr(ans1,"row.names")<- attr(res1,"row.names")  ident

Re: [R] How to extract last value in each group

2013-08-14 Thread peter dalgaard
t;>> } >>> >>> Bill Dunlap >>> Spotfire, TIBCO Software >>> wdunlap tibco.com >>> >>> >>>> -Original Message- >>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] >>>> On Behalf

Re: [R] How to extract last value in each group

2013-08-14 Thread David Winsemius
> >> >>> -----Original Message----- >>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >>> Behalf >>> Of arun >>> Sent: Wednesday, August 14, 2013 1:08 PM >>> To: Noah Silverman >>> Cc: R help

Re: [R] How to extract last value in each group

2013-08-14 Thread Michael Hannon
x == max(x, ] > >> } > >> f2 <- function (dataFrame) { > >> dataFrame[cumsum(with(dataFrame, tapply(Time, list(Date), FUN = > which.max))), ] > >> } > >> > >> Bill Dunlap > >> Spotfire, TIBCO Software >

Re: [R] How to extract last value in each group

2013-08-14 Thread Steve Lianoglou
rame, tapply(Time, list(Date), FUN = >> which.max))), ] >> } >> >> Bill Dunlap >> Spotfire, TIBCO Software >> wdunlap tibco.com >> >> >>> -----Original Message----- >>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-

Re: [R] How to extract last value in each group

2013-08-14 Thread Steve Lianoglou
; 4 06/01/2010 1700 136.55 136.55 136.55 136.55 1 0 >> 11 06/02/2010 338 136.80 136.80 136.80 136.80 3 0 >> >> #or >> dat1[as.logical(with(dat1,ave(Time,Date,FUN=function(x) x==max(x,] >> #Date Time O H L C U D >> #4 06/01/2010 1700 136.5

Re: [R] How to extract last value in each group

2013-08-14 Thread William Dunlap
ware wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of arun > Sent: Wednesday, August 14, 2013 1:08 PM > To: Noah Silverman > Cc: R help > Subject: Re: [R] How to extract last value

Re: [R] How to extract last value in each group

2013-08-14 Thread Noah Silverman
10 338 136.80 136.80 136.80 136.80 3 0 > A.K. > > > > > ----- Original Message ----- > From: Noah Silverman > To: "R-help@r-project.org" > Cc: > Sent: Wednesday, August 14, 2013 3:56 PM > Subject: [R] How to extract last value in each group > > Hello

Re: [R] How to extract last value in each group

2013-08-14 Thread arun
ent: Wednesday, August 14, 2013 3:56 PM Subject: [R] How to extract last value in each group Hello, I have some stock pricing data for one minute intervals. The delivery format is a bit odd.  The date column is easily parsed and used as an index for an its object.  However, the time column is

[R] How to extract last value in each group

2013-08-14 Thread Noah Silverman
Hello, I have some stock pricing data for one minute intervals. The delivery format is a bit odd. The date column is easily parsed and used as an index for an its object. However, the time column is just an integer (1:1807) I just need to extract the *last* entry for each day. Don't actuall