zoo (version 1.3-0)

read.zoo: Read zoo Series via read.table

Description

read.zoo is a convenience function for reading "zoo" series from text files.

Usage

read.zoo(file, format = "", tz = "", FUN = NULL, regular = FALSE, ...)

Arguments

file
character giving the name of the file which the data are to be read from. See read.table for more information.
format
date format argument passed to as.Date.character.
tz
time zone argument passed to as.POSIXct.
FUN
a function for computing the index from the first column of the data. See details.
regular
logical. Should the series be coerced to class "zooreg" (if the series is regular)?
...
further arguments passed to read.table.

Value

  • An object of class "zoo" (or "zooreg").

Details

read.zoo is a convenience function which should make it easier to read data from a text file and turn it into a "zoo" series immediately. read.zoo reads the data file via read.table(file, ...). The first column of the resulting data is interpreted to be the index, the remaining columns the corresponding data. (If the file only has only column then that is assumed to be the data column and 1, 2, ... are used for the index.) To assign the appropriate class to the index, FUN can be specified and is applied to the first column. By default, read.zoo uses as.Date(as.character(x), format = format) if format is specified and as.POSIXct(as.character(x), tz = tz) if tz is specified; otherwise it tries to guess between "numeric", "Date" and "POSIXct".

If regular is set to TRUE and the resulting series has an underlying regularity, it is coerced to a "zooreg" series.

See Also

zoo

Examples

Run this code
## turn *numeric* first column into yearmon index
z <- read.zoo("foo.csv", sep = ",", FUN = as.yearmon)

## turn *character* first column into Date index
z <- read.zoo("foo.tab", format = "%m/%d/%Y")

Run the code above in your browser using DataCamp Workspace