Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are almost all the way there. All you need to do now is create a zoo-isch version of that data and map it to the aggregate.zoo code. Since you want to categorize by both time and by type your second argument to aggregate.zoo must be a bit more complex and you want counts rather than means so your should use length(). I do not think that <code>count</code> is a base R or zoo function and the only <code>count</code> function I see in my workspace comes from pkg:plyr so I don't know how well it would play with aggregate.zoo. <code>length</code> works as most people expect for vectors but is often surprises people when working with data.frames. If you do not get what you want with <code>length</code>, then you should see if <code>NROW</code> works instead (and with your data layout they both succeed): With the new data object it is necessary to put the type argument first. AND it surns out the aggregate/zoo only handles single category classifiers so you need to put in the as.vector to remove it zoo-ness:</p> <pre><code>with(cured_data, aggregate(as.vector(x), list(type = type, interval=as.factor(time(x) - as.numeric(time(x)) %% 360)), FUN=NROW) ) # interval x #1 2011-09-22 09:24:00 12 #2 2011-09-22 09:24:00 11 </code></pre> <p>This is an example modified from where you got the code (an example on SO by WizaRd Dirk): <a href="https://stackoverflow.com/questions/7528571/aggregate-count-occurences-of-values-over-arbitrary-timeframe">Aggregate (count) occurences of values over arbitrary timeframe</a></p> <pre><code>tt &lt;- seq(10, 2000, 10) x &lt;- zoo(tt, structure(tt, class = c("POSIXt", "POSIXct"))) aggregate(as.vector(x), by=list(cat=as.factor(x), tms = as.factor(index(x) - as.numeric(index(x)) %% 600)), length) cat tms x 1 1 1969-12-31 19:00:00 26 2 2 1969-12-31 19:00:00 22 3 3 1969-12-31 19:00:00 11 4 1 1969-12-31 19:10:00 17 5 2 1969-12-31 19:10:00 28 6 3 1969-12-31 19:10:00 15 7 1 1969-12-31 19:20:00 17 8 2 1969-12-31 19:20:00 16 9 3 1969-12-31 19:20:00 27 10 1 1969-12-31 19:30:00 8 11 2 1969-12-31 19:30:00 4 12 3 1969-12-31 19:30:00 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload