r - How to split a chron date & time object in zoo for aggregation -


I have imported data into a zoo item with a gap of five minutes, where the index is a chronological order with both date and time Is:

> D (09/09/09 16:45:10) 13.2 5.8 (09/09/09 16:50:10) 8.3 0.7 (09/09/09 16:55:10) ) 4.7 0.7 (09/09/09 17:00:10) 6.6 0.7 (09/09/09 17:05:10) 4.6 0.7

I am trying to gather at quarterly intervals .

I found a way to do this by converting a string, but now the output is no longer a zoo.

> r = data.frame (total (d, trunk (cron (times = substr (as Cheuchar (index (d)), 11, 18)), "00:15:00" , Mean)> 00 00:00 0.5644444 00:15:00 0.5400000 00:30:00 0.5488889 00: 45:00 0.6155556 01:00:00 0.3422222 

When I can plot it, then I It was trying to do it basically. I came to know that with the zoo, the whole day and hour can be done, but I could not be divided into hours.

I do not believe there is any way to do this bird You have fallen in the house or time, but you can create your own function using a little math. Here you can go:

  trunc.minutes <- function (x, n. Minutes) {if (! (X, "times")) x <- as.chron (x) x <- as.numeric (x) sec & lt; - round (24 * 3600 * abs (X - floor (x))) H <- (sec% /% (n.minutes * 60)) / (60 / n.minutes) hours & lt; - as.integer (h) minute & lt; - (h %% hour) * 60 days (date = fourth: date (x), time = time (paste (hour, minute, "00", sep = ":")))}  

Here is an example of use:

  dts & lt; - chron :: dates (c ("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")) TMS & Lt; - times (c) ("23:03:20", "23:29:56", "01:03:30", "18:21:03", "16:56:26")) x & lt ; - Circle (date = DTS, times = TMS) # Original dates X [1] (02/27/92 23:03:20) (02/27/92 22:29:56) (01/14/92 01: 03:30) [4] (02/28/92 18:21:03) (02/01/92 16:56:26) trunc.minutes (x, 15) # 15-minute intervals new dates [1] (02/27/92 23:00:00) (02/27/92 22:15:00) (01/14/92 01:00:00) [4] (02/28/92 18:15:00 ) (02/01/92 16:45:00) trunc.minutes (x, 30) # 30 minute intervals new dates [1] (02/27/92 23:00:00) (02/27/92) 22:00:00) (01 / 14/92 01:00:00) [4] (02/28/92 18:00:00) (02/01/92 16:30:00)  < / Pre> 

Finally, you can now use this function to collect data:

  ts.zoo & lt; Use zodiac (rnorm (5), x) # a zoo time series  

or just use these new dates for aggregation (see how it increases the second example because in that window Have two values):

  & gt; Total (TSZU, trunk Minutes (X, 15), meaning) (01/14/92 01:00:00) (02/01/92 16:45:00) (02/27/92 23:00: 00 ) (02/27/92 23:15:00) -0.673865 9 -0.4844803 0.7 9 68155 -1.3571121 (02/28/92 18:15:00) 0.7625861> Total (TSZU, trunk. Minutes (x, 30), mean) (01/14/92 01:00:00) (02/01/92 16:30:00) (02/27/92 23:00: 00 ) (02/28/92 18:00:00) -0.673865 9 -0.4844803 -0.2801483 0.7625861  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -