Learn R Programming

timeSeries (version 4041.111)

sample: Resample 'timeSeries' objects

Description

Takes a sample of the specified size from the elements of a "timeSeries".

Usage

# S4 method for timeSeries
sample(x, size, replace = FALSE, prob = NULL)

Value

an object from class "timeSeries"

Arguments

x

an object from class "timeSeries".

size

a non-negative integer giving the number of items to choose.

replace

sample with replacement if TRUE, otherwise without replacement.

prob

a vector of probability weights for obtaining the elements of the vector being sampled.

Details

The function takes a sample of size size from the elements of the time series with or without replacement depending on argument replace. The result is returned as a "timeSeries" object.

For details about the arguments see the documentation of base:sample.

See Also

sample (sample in base R),

sample (the "timeDate" method)

Examples

Run this code
## Monthly Calendar Series -    
   x <- daily2monthly(LPP2005REC[, 1:2])[3:14, ]
   
set.seed(1234)
## Resample the Series with respect to the time stamps -    
   resampled <- sample(x)
   resampled
   is.unsorted(resampled)

Run the code above in your browser using DataLab