[R] aggregating dates

Mulholland, Tom Tom.Mulholland at dpi.wa.gov.au
Mon Jan 31 07:04:09 CET 2005


This seems to work

toPOSIX <- function(x){
  y <- x -  as.numeric(ISOdate(2005,1,1))
  z <- ISOdate(2005,1,1) + y
  return(z)
  }

test <- as.numeric(ISOdate(2005,3,1) )
toPOSIX(test)

But whether one should be doing this I don't know. There are certainly functions that play aorund with the POSIX format, I have always assumed that I'm missing something fundamental. But I have always found it easier to write a function like this than to find out what I should have done to keep the format intact in the first place.

Tom

The caveat is the critical or otherwise nature of the endeavour. If it matters, find the right answer or convince yourself that this code works.

> -----Original Message-----
> From: Paul Sorenson [mailto:Paul.Sorenson at vision-bio.com]
> Sent: Monday, 31 January 2005 1:17 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] aggregating dates
> 
> 
> I have a frame which contains 3 columns:
> 
> "date" "defectnum" "state"
> 
> And I want to get the most recent state change for a given 
> defect number.  date is POSIXct.
> 
> I have tried:
> 	aggregate(ev$date, by=list(ev$defectnum), max)
> 
> Which appears to be working except that the dates seem to 
> come back as integers (presumably the internal representation 
> of POSIXct).
> 
> When I execute max(ev$date) the result remains POSIXct.
> 
> I have been dredging through the help among DateTimeClasses 
> and haven't found a function that converts these integers to 
> some kind of date class.  Or a method for using aggregate 
> which doesn't perform the conversion in the first place.
> 
> Any clues?
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list