Learn R Programming

hydroTSM (version 0.3-4)

izoo2rzoo: Irregular Zoo -> Regular Zoo

Description

It takes an irregular (with missing dates) zoo object and convert it into a regularly spaced object within the time period defined by from and to, by filling the missing values with 'NA'.

Usage

izoo2rzoo(x, ...)

## S3 method for class 'default': izoo2rzoo(x, from= start(x), to= end(x), date.fmt= "%Y-%m-%d", tstep= "days", ...) ## S3 method for class 'zoo': izoo2rzoo(x, from= start(x), to= end(x), date.fmt= "%Y-%m-%d", tstep= "days", ...)

Arguments

x
time series of zoo class (very likely read with some user-defined procedure, and with some missing values for particular days/months/years)
from
Character indicating the starting date for creating the sequence. It has to be in the format indicated by date.fmt. The default value corresponds to the date of the first element of x.
to
Character indicating the ending date for creating the sequence. It has to be in the format indicated by date.fmt. The default value corresponds to the date of the last element of x.
date.fmt
character indicating the format in which the dates are stored in from and to, e.g. %Y-%m-%d. See format in as.Date.
tstep
character, indicating the time step used for sampling x, e.g., days, months, years.
...
further arguments passed to or from other methods

Details

If the full time period of x is a subset of the time period defined by from and to, the time period of the resulting zoo is the one defined by from and to, assigning 'NA' to all the dates in which x do not have a value.

See Also

vector2zoo

Examples

Run this code
x <- 1:9

## February 29th is missing:
dates <- c("1964-02-25", "1964-02-26", "1964-02-27", "1964-02-28", "1964-03-01", 
           "1964-03-02", "1964-03-03", "1964-03-04", "1964-03-05")

## From 'character' to 'Date' class
dates <- as.Date(dates)

## From 'numeric' to 'zoo' class
x <- vector2zoo(x, dates) #Feb 29th is still missing

## Feb 29th is added to 'y' with a missing value
y <- izoo2rzoo(x, from=dates[1], to=dates[length(dates)])

## Creating a regular sequence from February 1st to the end of March,
## assigning 'NA' to the days in which 'x' do not have a value.
y <- izoo2rzoo(x, from="1964-02-01", to="1964-03-31")

Run the code above in your browser using DataLab