resolution {crunch}R Documentation

Methods for Datetime variable resolutions

Description

Datetime data has a "resolution", the units of the values. resolution() exposes that property and ⁠resolution<-⁠ lets you set it. "Rollups" are a way of binning datetime data into meaningful units. rollup() lets you create an expression that you can query with. Datetime variables also have a rollupResolution() attribute that is the default resolution they will roll-up to, if not specified in rollup(); ⁠rollupResolution<-⁠ lets you set that.

Usage

resolution(x)

resolution(x) <- value

rollup(x, resolution = rollupResolution(x))

rollupResolution(x)

rollupResolution(x) <- value

Arguments

x

a Datetime variable

value

a resolution string. Valid resolutions in Crunch are c("Y", "Q", "M", "W", "D", "h", "m", "s", "ms"). NULL is also valid for ⁠rollupResolution<-⁠ but not for ⁠resolution<-⁠.

resolution

Same as value, in rollup(). This may be NULL, in which case the server will determine an appropriate resolution based on the range of the data.

Details

Note that resolution is a property of the data while rollupResolution is metadata. Setting resolution alters the column data, and if setting a more coarse resolution (e.g. going from "s" to "m"), it cannot be reversed. Setting rollupResolution is non-destructive.

Value

resolution() and rollupResolution() return the resolution string for datetime variables, NULL otherwise. The setters return the variable entity after modifying the state on the server. rollup() returns a CrunchExpr expression.

Examples

## Not run: 
resolution(ds$starttime)
## [1] "ms"
resolution(ds$starttime) <- "s"
rollup(ds$starttime)
rollup(ds$starttime, "D")
rollupResolution(ds$starttime) <- "D"
crtabs(~ rollup(starttime), data = ds)

## End(Not run)

[Package crunch version 1.30.4 Index]