[R] correct my method of estimating mean of two POSIXlt data frames

gotrout@gmail.com gotrout at gmail.com
Tue Oct 5 19:27:17 CEST 2004


Hello,  I searched the archives but could not come to a solution.  I
have to two columns of information

t_start_cdt looks like:
> t_start_cdt[1:4]
[1] "2003-07-09 11:02:25" "2003-07-09 11:10:25" "2003-07-09 11:30:25"
[4] "2003-07-09 12:00:25"
> class(t_start_cdt)
[1] "POSIXt"  "POSIXlt"

t_end_cdt looks like:
> t_end_cdt[1:4]
[1] "2003-07-09 11:02:35" "2003-07-09 11:10:35" "2003-07-09 11:30:35"
[4] "2003-07-09 12:00:35"
> class(t_end_cdt)
[1] "POSIXt"  "POSIXlt"


I'd like to estimate the mean of each "pair".  For example, the mean
of (t_start_cdt[1] and t_end_cdt[1]).  The only way I could do this
is:
hi <- cbind(as.matrix(as.POSIXct(t_start_cdt)),
as.matrix(as.POSIXct(t_end_cdt)))
hi <- apply(hi, MARGIN=1, FUN=mean)
class(hi) <- c("POSIXt", "POSIXct")
t_mean_cdt <- as.POSIXlt(hi)
rm(hi)

What am I missing conceptually about POSIXlt, and what is the better method?
thanks,
Mike




More information about the R-help mailing list