Learn R Programming

grates (version 1.4.3)

int_period_class: Integer-period class (Experimental)

Description

<grates_int_period> objects represent groupings of n consecutive integers from 0.

Usage

# S3 method for default
as_int_period(x, n = 1L, ...)

# S3 method for integer as_int_period(x, n = 1L, ...)

# S3 method for double as_int_period(x, n = 1L, ...)

new_int_period(x = integer(), n = 1L)

is_int_period(xx)

as_int_period(x, n, ...)

Value

A <grates_int_period> object.

Arguments

x, xx

R objects.

For as_int_period() this is the object to be coerced.

For new_int_period() this represents the number of n integer periods from 0.

double vectors will be converted via as.integer(floor(x)).

n

[integer]

Number of integers that are being grouped. Must be greater than 0.

...

Not currently used.

Details

as_int_period() is a generic for coercing input in to <grates_int_period> objects. For numeric input it coerces it's input x first via x <- as.integer(floor(x)) and then via integer division by n (i.e. x %/% n).

new_int_period() is a minimal constructor for <grates_period> objects aimed at developers. It takes, as input, the number of integer periods and the value of n.

Examples

Run this code

# coercion
as_int_period(1:10, n = 3)

# direct construction
stopifnot(
    identical(
        as_int_period(1:10, n = 3),
        new_int_period(c(0, 0, 1, 1, 1, 2, 2, 2, 3, 3), n = 3)
    )
)



Run the code above in your browser using DataLab