Vector -> Zoo

Share:

Description

Transform a numeric vector and its corresponding dates into a zoo object.

Usage

1
vector2zoo(x, dates, date.fmt = "%Y-%m-%d")

Arguments

x

numeric vector

dates

character, factor, Date or POSIXct object with the dates corresponding to each element of x. Valid object class for dates are: character, factor, Date, POSIXct

date.fmt

character indicating the format in which the dates are stored in dates, e.g. %Y-%m-%d. See ‘Details’ section in strptime.
ONLY required when class(dates)=="factor" or class(dates)=="character".

Value

a zoo object, with values given by x and time stamps given by dates

Author(s)

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

See Also

zoo, izoo2rzoo, dip, mip, yip

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
##
## Example1: creating daily data

# Generating a numeric variable (e.g., read from the outputs of an hydrological model)
x <- 1:31

# Generating the dates corresponding to the previous values
dates <- dip("1961-01-01", "1961-01-31")

## Transforming from 'numeric' to 'zoo' class
z <- vector2zoo(x, dates)

##
## Example2: creating hourly data

# Generating a numeric variable
x <- rnorm(7)

# Generating hourly times since 17:00:00 up to 23:00:00 for 2012-Oct-15
dates <- ISOdatetime(2012, 10, 15, 17:23, 00, 0)

## Transforming from 'numeric' to 'zoo' class
z <- vector2zoo(x, dates)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.