write.zoo are convenience functions for reading
"zoo" series from/to text files. They are convenience
read.delim2 instead of
read.table additional functions
read.csv.zoo etc. are provided.
read.zoo(file, format = "", tz = "", FUN = NULL, regular = FALSE, index.column = 1, drop = TRUE, FUN2 = NULL, split = NULL, aggregate = FALSE, ..., text, read = read.table) write.zoo(x, file = "", index.name = "Index", row.names = FALSE, col.names = NULL, ...)
read.csv.zoo(..., read = read.csv) read.csv2.zoo(..., read = read.csv2) read.delim.zoo(..., read = read.delim) read.delim2.zoo(..., read = read.delim2)
read.zoo returns an object of class
character string or strings giving the name of the file(s)
which the data
are to be read from/written to. See
write.table for more information. Alternatively,
file can be a
connection or a
resulting from a previous
read.table call) that
is subsequently processed to a
date format argument passed to
time zone argument passed to
a function for computing the index from the first column of the data. See details.
logical. Should the series be coerced to class
(if the series is regular)?
numeric vector or list. The column names or numbers of the data frame
in which the index/time is stored. If the
is used and
"NULL" is among its components then
index.column refers to the column numbers after the columns
colClasses have been removed.
If specified as a list then one argument will be passed to argument
FUN per component so that,
index.column = list(1, 2) will cause
FUN(x[,1], x[,2], ...) to be called whereas
index.column = list(1:2) will cause
FUN(x[,1:2], ...) to be called where
x is a data frame of
characters data. Here
... refers to
tz, if they specified as arguments.
index.column = 0 can
be used to specify that the row names be used as the index. In the case that
no row names were input sequential numbering is used.
index.column is specified as an ordinary vector then if it has the
same length as the number of arguments of
FUN2 in the
FUN2 is specified and
FUN is not)
index.column is converted to a
list. Also it is always converted to a list if it has length 1.
logical. If the data frame contains just a single data column, should the second dimension be dropped?
character with name of the index column in the written data file.
logical. Should row names be written? Default is
because the row names are just character representations of the index.
logical. Should column names be written? Default is to
write column names only if
x has column names.
function. It is applied to the time index after
FUN and before
FUN is not specified
FUN2 is specified then only
FUN2 is applied.
NULL or column number or name or vector of numbers or
names. If not NULL then the data is assumed to be in long format and is
split according to the indicated columns. See the R
reshape command for description of long data.
split = Inf then the first of each run among the times are made into
a separate series, the second of each run and so on. If
split= -Inf then
the last of each run is made into a separate series, the second last
and so on.
logical or function. If set to
is applied to the zoo object created to compute the
mean of all values with
the same time index. Alternatively,
aggregate can be set to any other
function that should be used for aggregation.
FALSE (the default), no aggregation is performed and a warning
is given if there are any duplicated time indexes. Note that most
zoo functions do not accept objects with duplicate time indexes.
further arguments passed to other functions. In the
the arguments are passed to the function specified in
file is a
data.frame already). In
arguments are passed to
file is not supplied and this is, then
data are read from the value of
text via a text connection.
See below for an example.
function. The function for reading
file (unless it is
read.zoo is a convenience function which should make it easier
to read data from a text file and turn it into a
read.zoo reads the data file via
index.column (by default the first) of the resulting data is
interpreted to be the index/time, 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.
To process the index,
FUN with the index as the
first argument. If
FUN is not specified, the following default is employed:
file is a data frame with a single
index column that appears to be a time index already, then
FUN = identity is used.
The conditions for a readily produced time index are: It is not
factor (and the arguments
format must not be specified).
(b) If the conditions from (a) do not hold then the following strategy is used.
If there are multiple index columns they are pasted together with a space between each.
Using the (pasted) index column: (1) If
tz is specified then the
index column is converted to
POSIXct. (2) If
format is specified
then the index column is converted to
Date. (3) Otherwise, a heuristic
attempts to decide between
trying them in that order (which may not always succeed though). By default,
only the standard date/time format is used. Hence, supplying
is necessary if some date/time format is used that is not the default. And even
if the default format is appropriate for the index, explicitly supplying
FUN or at least
tz typically leads to more
reliable results than the heuristic.
regular is set to
TRUE and the resulting series has an
underlying regularity, it is coerced to a
To employ other functions than
read.table to read the initial data,
further convenience interfaces
read.csv.zoo etc. are provided.
write.zoo is a convenience function for writing
to text files. It first coerces its argument to a
a column with the index and then calls
vignette("zoo-read", package = "zoo") for detailed examples.