[R] aggregating dates
Gabor Grothendieck
ggrothendieck at myway.com
Mon Jan 31 15:56:41 CET 2005
Paul Sorenson <Paul.Sorenson <at> vision-bio.com> writes:
:
: 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
RNews 4/1 has an article with this and other date conversions.
: which doesn't perform the
: conversion in the first place.
You could sort ev by date and use aggregate on an index vector (untested):
ev <- ev[order(ev$date),]
ev[aggregate(1:nrow(ev), list(ev$defectnum), max),]
More information about the R-help
mailing list