Skip to contents

Objects and methods for class PeriodicVector.

Usage

PeriodicVector(x, period = length(x))

Arguments

x

the values for inidices from 1 to period, numeric.

period

the period, defaults to length(x).

Details

A \(p\)-periodic vector, \(X\), is such that \(X_{i+pk} = X_i\) for any integers \(i,k\).

Class PeriodicVector stores the values of \(X_1,\ldots,X_p\) and provides indexing methods for extracting and setting its elements.

Value

an object from class "PeriodicVector"

Objects from the Class

Objects can be created by calls of the form new("PeriodicVector", ...) or more conveniently by using "PeriodicVector()".

Slots

.Data:

Object of class "numeric" ~~

period:

Object of class "numeric" ~~

Extends

Class "numeric", from data part. Class "vector", by class "numeric", distance 2. Class "atomicVector", by class "numeric", distance 2. Class "index", by class "numeric", distance 2.

Class "numLike", by class "numeric", distance 2.

Class "number", by class "numeric", distance 2. Class "replValue", by class "numeric", distance 2.

Methods

"PeriodicVector" methods are defined for "[" and "[<-". Arithmetic operations just inherit the recycling rules from "numeric".

[

signature(x = "PeriodicVector", i = "ANY", j = "ANY", drop = "ANY"): ...

[

signature(x = "PeriodicVector", i = "ANY", j = "missing", drop = "ANY"): ...

[

signature(x = "PeriodicVector", i = "missing", j = "ANY", drop = "ANY"): ...

[

signature(x = "PeriodicVector", i = "missing", j = "missing", drop = "ANY"): ...

[<-

signature(x = "PeriodicVector", i = "ANY", j = "ANY", value = "ANY"): ...

[<-

signature(x = "PeriodicVector", i = "missing", j = "ANY", value = "ANY"): ...

Author

Georgi N. Boshnakov

See also

PeriodicVector

Examples

PeriodicVector(1:4, period = 4)
#> An object of class "PeriodicVector"
#> [1] 1 2 3 4
#> Slot "period":
#> [1] 4
#> 
PeriodicVector(1:4) ## same
#> An object of class "PeriodicVector"
#> [1] 1 2 3 4
#> Slot "period":
#> [1] 4
#> 
new("PeriodicVector", 1:4, period = 4)
#> An object of class "PeriodicVector"
#> [1] 1 2 3 4
#> Slot "period":
#> [1] 4
#> 

## if period is given but x is missing, the vector is filled with NA's
PeriodicVector(period = 4)
#> An object of class "PeriodicVector"
#> [1] NA NA NA NA
#> Slot "period":
#> [1] 4
#> 

## this throws error, since length(x) != period:
##    PeriodicVector(1:3, period = 4)

## extract
x <- PeriodicVector(1:4)
x[3:12]
#>  [1] 3 4 1 2 3 4 1 2 3 4
x[c(3, 7, 11, 15)]
#> [1] 3 3 3 3

# any indices in (-Inf, Inf) work
x[0]
#> [1] 4
x[-3:0]
#> [1] 1 2 3 4

## "[<-" works on the underling vector
x[1] <- 11; x
#> An object of class "PeriodicVector"
#> [1] 11  2  3  4
#> Slot "period":
#> [1] 4
#> 

## modulo indexing works also in assignments:
x[5] <- 21; x
#> An object of class "PeriodicVector"
#> [1] 21  2  3  4
#> Slot "period":
#> [1] 4
#> 

## empty index returns the underlying vector
x[]
#> [1] 21  2  3  4

## the recycling rule applies on assignment
x[] <- 9; x
#> An object of class "PeriodicVector"
#> [1] 9 9 9 9
#> Slot "period":
#> [1] 4
#> 
x[] <- 1:2; x
#> An object of class "PeriodicVector"
#> [1] 1 2 1 2
#> Slot "period":
#> [1] 4
#> 

## this gives warning, as for numeric vectors
##     x[] <- 8:1
## compare:
##     x <- 1:4
##     x[] <- 8:1

## arithmetic works as usual:
2 * x
#> An object of class "PeriodicVector"
#> [1] 2 4 2 4
#> Slot "period":
#> [1] 4
#> 
x + 1:4
#> An object of class "PeriodicVector"
#> [1] 2 4 4 6
#> Slot "period":
#> [1] 4
#> 
## x + 1:3 # warning - '... a multiple ...'