[R] How to get back POSIXct format after calculating with hist() results

From: <Peter.Marx_at_knorr-bremse.com>
Date: Sat 26 Aug 2006 - 01:37:31 EST


Hi,

I have a casting/formatting question on hist.POSIXt:

The histogram plot from POSIXct works perfect (with help of Prof. Ripley -thanks!).
When processing the hist(plot=FALSE) output and then plotting the results over the x-axis (bins) coming from hist(), I lose the date/time labels, getting instead integers displayed.

Trying to cast the $breaks with as.POSIXct gives silly results with StarTrek-like years.

What is the proper way to get back the old YY-MM-DD hh:mm:ss labels ?

Peter

> str(logins)

`data.frame': 25792 obs. of 1 variable:  $ DateTime:'POSIXct', format: chr "2006-08-01 00:00:02" "2006-08-01 00:00:25" "2006-08-01 00:00:41" ...

> login_bins<-hist(samples$DateTime, "hours", freq=TRUE,plot=FALSE)

> str(login_bins)
List of 7
 $ breaks : num [1:337] 1.15e+09 1.15e+09 1.15e+09 1.15e+09 1.15e+09 ...
 $ counts : int [1:336] 6 10 45 25 40 87 257 356 309 214 ...  $ intensities: num [1:336] 0.000233 0.000388 0.001744 0.000969 0.001550 ...
 $ density : num [1:336] 6.46e-08 1.08e-07 4.85e-07 2.69e-07 4.31e-07 ...
 $ mids : num [1:336] 1.15e+09 1.15e+09 1.15e+09 1.15e+09 1.15e+09 ...
 $ xname : chr "logins$DateTime"
 $ equidist : logi TRUE

... Then I do some calculations with the login_bins$counts, resulting in a new vector:

>str(userabs)

 int [1:336] 1 -3 34 39 68 127 347 641 844 943 ...

When I now plot this y over the x-axis coming from the previous histogram x-axis with

>plot(login_bins$mids, userabs)

I get the x-axis of labelled with the nums 1154400000, 1154800000... (number of seconds since 1970 ?)

Trying to convert this gives funny results.

>as.POSIXct(as.Date(login_bins$mids[1]))
[1] "2568-10-12 02:00:00 W. Europe Daylight Time"

> as.POSIXct(as.Date(login_bins$mids[2]))
[1] "2578-08-21 02:00:00 W. Europe Daylight Time"



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 and provide commented, minimal, self-contained, reproducible code. Received on Sat Aug 26 06:49:56 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 26 Aug 2006 - 08:26:24 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.