First element in a data.table aggregation
data.table, r
Solution
I managed to find the solution. The query to get the first element is to just subset that column's first value using `[`:
data[, list(value[1], max(value), min(value), last(value)),by=time]
Maybe it helps someone.
Problem
I have a `data.table` of tick data, which I want to aggregate into seconds timeframe. While getting `max`, `min` and `last` is pretty straightforward: ``` data[, list(max(value), min(value), last(value)), by=time] ``` I am struggling to get the first datapoint which corresponds to a certain second timestamp. There is nothing in the manual. Is there an easy way to do it, like say, SQL `TOP`?