as.Text {crunch}R Documentation

as.* methods for variables

Description

Use the as.* family of functions to make a derived copy of a variable that has been converted into a new type.

Usage

as.Text(x, ...)

as.Numeric(x)

as.Categorical(x, ...)

as.Datetime(x, format = "%Y-%m-%d %H:%M:%S", resolution, offset)

## S4 method for signature 'CrunchVariable'
as.Numeric(x)

## S4 method for signature 'CrunchVariable'
as.Text(x, format)

## S4 method for signature 'CrunchVariable'
as.Categorical(x, format)

## S4 method for signature 'CrunchVariable'
as.Datetime(x, format = "%Y-%m-%d %H:%M:%S", resolution, offset)

## S3 method for class 'CrunchVariable'
as.double(x, ...)

## S3 method for class 'CrunchVariable'
as.character(x, ...)

## S4 method for signature 'CrunchExpr'
as.Numeric(x)

## S4 method for signature 'CrunchExpr'
as.Text(x, format)

## S4 method for signature 'CrunchExpr'
as.Categorical(x, format)

## S4 method for signature 'CrunchExpr'
as.Datetime(x, format = "%Y-%m-%d %H:%M:%S", resolution, offset)

## S3 method for class 'CrunchExpr'
as.double(x, ...)

## S3 method for class 'CrunchExpr'
as.character(x, ...)

Arguments

x

a Crunch variable to derive and convert to a new type

...

additional arguments for as.character and as.numeric, ignored when used with Crunch variables

format

for as.Datetime, when the variable in x is a text or categorical variable, format is the typographical format that the datetime is already formatted in that needs to be parse from (default: "%Y-%m-%d %H:%M:%S"); for as.Text and as.Categorical, is the typographical format that the datetime is to be formatted as (e.g. "%Y-%m-%d %H:%M:%S" for "2018-01-08 12:39:57", the default if no rollup resolution is specified on the source variable. If a rollup resolution is specified, a reasonable default will be used.).

resolution

for as.Datetime, when the variable in x is a numeric variable, the resolution of the number (e.g. "ms" for milliseconds, "s" for seconds, etc. see expressions for more information about valid values.)

offset

for as.Datetime, when the variable in x is a numeric the, a character of the offset to count from in the shape "2018-01-08 12:39:57". If not supplied, Crunch's default of 1970-01-01 00:00:00 will be used.

Details

Each type of Crunch variable (text, numeric, categorical, etc.) has an ⁠as.*⁠ function (as.Text, as.Numeric, and as.Categorical respectively) that takes the input given as x, and makes a new derived variable that is now of the type specified. See below for detailed examples.

For as.Text and as.Numeric, aliases to the R-native functions as.character and as.numeric are provided for convenience.

Value

a CrunchExpr to be used as the derivation

Examples

## Not run: 
# ds$v1 is of type Text
is.Text(ds$v1)
# [1] TRUE

# that has strings of numbers
as.vector(ds$v1)
# [1] "32"   "8"    "4096" "1024"

# convert this to a numeric variable with the alias `v1_numeric`
ds$v1_numeric <- as.Numeric(ds$v1)

# the values are the same, but are now numerics and the type is Numeric
as.vector(ds$v1_numeric)
# [1]   32    8 4096 1024
is.Numeric(ds$v1_numeric)
# [1] TRUE

# this new variable is derived, so if new data is appended or streamed, the
# new rows of data will be updated.
is.derived(ds$v1_numeric)
# [1] TRUE

## End(Not run)

[Package crunch version 1.30.4 Index]