The solution I came up with myself was simply to coerce the integer back to 
POSIXct:

        class(ev$date) = "POSIXct"

Can't say it is the right way to do it but it seem to work.

A second related problem I haven't been able to solve as yet is how to include 
"incidents" columns (those not in 'x' or 'by') in an aggregate.

        names(ev): "date" "defectnum" "state"
 
        aggregate(ev$date, by=list(ev$defectnum), max)

This returns only the date and defectnum, I also need the state.

I tried writing my own aggregator function:
        maxevent = function(events) {
            events[which.max(events$date),]
        }

        aggregate(ev, by=list(ev$defectnum), maxevent)

But I get:

        Error in "[.default"(events, which.max(events$date), ) : 
          incorrect number of dimensions

I am trying to retrieve only the rows of ev with the latest date for a given 
defectnum.

cheers

> Message: 29
> Date: Mon, 31 Jan 2005 16:16:35 +1100
> From: "Paul Sorenson" <[EMAIL PROTECTED]>
> Subject: [R] aggregating dates
> To: <r-help@stat.math.ethz.ch>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain;     charset="iso-8859-1"
> 
> 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@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

Reply via email to