izoo2rzoo: Irregular Zoo -> Regular Zoo

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/izoo2rzoo.R

Description

It takes an irregular zoo object (with non-existing values for some dates) and converts it into a regularly spaced zoo object within the time period defined by from and to, by filling the missing dates with ‘NA’

Usage

1
2
3
4
5
6
7
izoo2rzoo(x, ...)

## Default S3 method:
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

irregular zoo object (vector or matrix) representing a time series (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 regularly spaced zoo object. The default value corresponds to the date of the first element of x
It has to be in the format indicated by date.fmt.

to

Character indicating the ending date for creating the regularly spaced zoo object. The default value corresponds to the date of the last element of x
It has to be in the format indicated by date.fmt.

date.fmt

character indicating the format in which the dates are stored in from and to, e.g. %Y-%m-%d. See ‘Details’ section in strptime

tstep

character, indicating the time step used for creating the time sequence going from from to to that will be used as time(x)
Valid values are (but not limited to) days, months, years, hours

...

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.

Value

a regularly spaced zoo object, with values given by x and time stamps going from from to to at intervals defined by tsteps

Author(s)

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

See Also

vector2zoo

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
##
## Example 1: Adding NA for February 29th to an existing zoo object

# dummy values and dates (February 29th is not present !)
x <- 1:9
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 <- zoo(x, dates) # Feb 29th is still missing

## Adding a missing value (NA in this case) for Feb 29th
y <- izoo2rzoo(x)

## checking the new length
length(y) # 1 element more than the original 'x' (Feb 29th)


##
## Example 2: Extending the original 'x' object 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")


##
## Example 3: Working with a zoo matrix
Y <- cbind(x,x)

# Adding a missing value (NA in this case) for Feb 29th in all the columns of Y
rY <- izoo2rzoo(Y, from="1964-02-25", to="1964-03-05")


##
## Example 4: Working with hourly data, from 01:00 to 10:00 on 12th December 2000
dates  <- ISOdatetime(2000, 12, 12, 1:10, 0, 0)
values <- 1:10
x      <- zoo(values, dates)

# removing values from 02:00 to 05:00 (not present at all in 'x', not even NA !)
x <- x[-c(2:5)]

#  Adding missing values (NA in this case) from 02:00 to 05:00
y <-  izoo2rzoo(x, date.fmt="%Y-%m-%d %H:%M:%S", tstep="hours")

hydroTSM documentation built on March 13, 2020, 2:23 a.m.