找回密码
 注册
查看: 4350|回复: 0

R语言 zoo包 read.zoo()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-10-2 07:53:40 | 显示全部楼层 |阅读模式
read.zoo(zoo)
read.zoo()所属R语言包:zoo

                                        Reading and Writing zoo Series
                                         阅读和写作动物园系列

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

read.zoo and write.zoo are convenience functions for reading and writing "zoo" series from/to text files. They are convenience interfaces to read.table and write.table, respectively.
read.zoo和write.zoo是"zoo"系列/文本文件的阅读和写作的便利功能。他们是read.table和write.table,分别便捷接口。


用法----------Usage----------


read.zoo(file, format = "", tz = "", FUN = NULL,
  regular = FALSE, index.column = 1, drop = TRUE, FUN2 = NULL,
  split = NULL, aggregate = FALSE, ..., text)
write.zoo(x, file = "", index.name = "Index", row.names = FALSE, col.names = NULL, ...)



参数----------Arguments----------

参数:file
character string or strings giving the name of the file(s)  which the data are to be read from/written to. See read.table and write.table for more information. Alternatively, in read.zoo, file can be a connection or a data.frame (e.g., resulting from a previous read.table call) that is subsequently processed to a "zoo" series.
字符串或字符串的文件(s)的数据要被读出/写入到给出的名称。见read.table和write.table的详细信息。另外,在read.zoo,file可以了connection或data.frame(例如,从以前的read.table叫),随后处理了 "zoo"系列。


参数:format
date format argument passed to FUN.
日期格式参数传递给FUN。


参数:tz
time zone argument passed to as.POSIXct.
时区参数传递给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)?
逻辑。该系列被强制转换为类"zooreg"(如果该系列产品是正规的)?


参数:index.column
numeric vector or list. The column names or numbers of the data frame  in which the index/time is stored.  If the read.table colClasses  argument is used and "NULL" is among its componennts then  index.column refers to the column numbers after the columns  corresponding to "NULL" in colClasses have been removed.   If specified as a list  then one argument will be passed to argument FUN per component so that,  for example, 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 format and/or 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. If index.column is specified as an ordinary vector then if it has the same length as the number of arguments of FUN (or FUN2 in the event that FUN2 is specified and FUN is not)  then index.column is converted to a list.  Also it is always converted to a list if it has length 1.
数值向量或列表。的列名或索引/时间存储在其中的数据框的数目。如果read.tablecolClasses参数是用来和"NULL"是在其componennts的那么index.column"NULL"在对应的列的列号后<X >已被删除。如果指定为一个列表,然后一个参数被传递到参数colClasses每个组件,这样一来,例如,FUN会导致index.column = list(1, 2)而被称为FUN(x[,1], x[,2], ...)会导致 index.column = list(1:2)FUN(x[,1:2], ...)是一个数据框的字符数据。这是x是指...和/或format,如果指定为参数。 tz可用于指定该行名称作为索引。在使用的情况下,没有行名称输入顺序编号。如果index.column = 0是作为一个普通的矢量指定的的参数index.column(或数量相同的长度,然后,如果它FUNFUN2指定事件FUN2是不是),那么FUN被转换到一个列表中。此外,它总是被转换到一个列表中,如果它的长度为1。


参数:drop
logical. If the data frame contains just a single data column, should the second dimension be dropped?
逻辑。如果数据框只包含一个单一的数据列,应被丢弃的第二个方面呢?


参数:x
a "zoo" object.
一个"zoo"对象。


参数:index.name
character with name of the index column in the written data file.   
字符写入数据文件的索引列的名称。


参数:row.names
logical. Should row names be written? Default is FALSE because the row names are just character representations of the index.
逻辑。行的名称写?默认是FALSE因为该行名称的字符表示的索引。


参数:col.names
logical. Should column names be written? Default is to write column names only if x has column names.
逻辑。列名写?默认是写只有x有列名的列名。


参数:FUN2
function. It is applied to the time index after  FUN and before aggregate. If FUN is not specified but FUN2 is specified then only FUN2 is applied.
功能。它被应用到后的时间索引FUN前aggregate。 FUN如果没有规定,但FUN2指定,那么只有FUN2。


参数:split
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. If split=Inf then the first of each run 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.  
NULL或列的编号或名称或向量的数字或名称。如果不为NULL,然后数据被假定为在长格式,并根据所指示的列被分割。长的数据说明,请参阅Rreshape命令。如果split=Inf然后每次运行的第一被做成一个单独的系列,第二每次运行等。如果split= -Inf然后每次运行最后做成一个单独的系列,倒数第二个等。


参数:aggregate
logical or function. If set to TRUE, then aggregate.zoo 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. If 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.  See aggregate.zoo.
逻辑或功能。如果设置为TRUE,然后aggregate.zoo应用到动物园创建的对象,同时指数计算mean的所有值。或者,aggregate可以设置为任何其他的功能,应用于聚合。如果FALSE(默认值),无聚集和一个警告信息,如果有任何重复的时间指标。请注意,大多数zoo函数不接受重复的时间索引对象。见aggregate.zoo。


参数:...
further arguments passed to read.table or write.table, respectively.
进一步的论据,分别传递给read.table或write.table。


参数:text
See argument of same name in read.table.
相同名称的参数read.table。


Details

详细信息----------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 column 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.
read.zoo是一个方便的功能,应该更容易从一个文本文件中读取数据,并立即把它变成一个"zoo"系列。 read.zoo读取文件通过read.table(file, ...)中的数据。所产生的数据列index.column(默认情况下,第一个)被解释为索引/时间,其余各列对应的数据。 (如果文件只有唯一的一列,然后被认为是数据列和1, 2, ...是用于索引)的索引,FUN可以指定分配适当的类和应用的第一列。

To process the index, read.zoo calls FUN with the index as the first argument.  If FUN is not specified then if there are multiple index columns they are pasted together with a space between each.  Using the index column or 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 among "numeric", "Date" and "POSIXct". If format and/or tz is specified then they are passed to the conversion function as well.
要处理的索引,read.zoo调用FUN作为第一个参数的索引。 FUN如果不指定,那么如果有多个索引列,他们之间的空间粘贴在一起。使用索引列或粘贴的索引列:1。如果tz指定的索引列转换为POSIXct。 2。如果format指定的索引列转换为Date。 3。否则,的启发式试图决定之间"numeric","Date"和"POSIXct"。如果format和/或tz指定他们传递的转换功能。

If regular is set to TRUE and the resulting series has an  underlying regularity, it is coerced to a "zooreg" series.
如果regular设置为TRUE和由此带来的一系列有一个基本的规律,它被强制转换为一个"zooreg"系列。

write.zoo is a convenience function for writing "zoo" series to text files. It first coerces its argument to a "data.frame", adds a column with the index and then calls write.table.
write.zoo写"zoo"系列文本文件是一个方便的功能。首先它的参数强制,添加一列的索引,然后调用"data.frame"到write.table。


值----------Value----------

read.zoo returns an object of class "zoo" (or "zooreg").
read.zoo返回的对象的类"zoo"("zooreg"的)。


注意----------Note----------

read.zoo works by first reading the data in using read.table and then processing it.  This implies that  if the index field is entirely numeric the default is to pass it to FUN or the built-in date conversion routine a number, rather than a character string.  Thus, a date field such as 09122007 intended to represent December 12, 2007 would be seen as 9122007 and interpreted as the 91st day  thereby generating an error.  
read.zoo的工作原理是第一次读取数据,在使用read.table然后再进行处理。这意味着,如果完全是数字的索引字段默认是将它传递给FUN或内置的日期转换例行程序数量,而不是一个字符串。因此,如日期字段09122007代表12月12,2007年将被视为9122007和解释的第91天,从而产生错误。

This comment also applies to trailing decimals so that if  2000.10 were intended to represent the 10th month of 2000 in fact it would receive 2000.1 and regard it as the first month of 2000 unless similar precautions were taken.
这个意见也适用于后小数因此,如果2000.10其实是因为它们代表2000年的第10个月的会收到2000.1,并把它作为2000年的第一个月,除非采取类似的预防措施。

In the above cases the index field should be specified to be "character" so that leading or trailing zeros are not dropped.  This can be done by specifying a "character" index column in the  "colClasses" argument, which is passed to read.table,  as shown in the examples below.
在上述情况下,索引字段应指定为"character"“这样开头或结尾零不下降。这可以通过指定一个"character"索引列的"colClasses"参数,该参数传递给read.table,如下面的例子所示。


参见----------See Also----------

zoo
zoo


实例----------Examples----------


## Not run: [#不运行:]
## turn *numeric* first column into yearmon index[#把数字第一列到yearmon指数]
## where number is year + fraction of year represented by month[#在数年+分数的一年为代表的一个月]
z <- read.zoo("foo.csv", sep = ",", FUN = as.yearmon)

## first column is of form yyyy.mm[#第一列的形式yyyy.mm]
## (Here we use format in place of as.character so that final zero [#(这里我们使用的格式,地点as.character,使最终的零]
## is not dropped in dates like 2001.10 which as.character would do.)[#不掉线2001.10,这as.character会做的日期一样。)]
f <- function(x) as.yearmon(format(x, nsmall = 2), "%Y.%m")
z <- read.zoo("foo.csv", header = TRUE, FUN = f)

## turn *character* first column into "Date" index[#把字符*第一列到“日期”指数]
## Assume lines look like: 12/22/2007 1 2[#假定行是这样的:12月22日1 2]
z <- read.zoo("foo.tab", format = "%m/%d/%Y")

# Suppose lines look like: 09112007 1 2 and there is no header[假设行的样子:09112007 2,有没有头]
z <- read.zoo("foo.txt", format = "%d%m%Y")

## csv file with first column of form YYYY-mm-dd HH:MM:SS[#csv文件,第一列的形式YYYY-MM-DD HH:MM:SS]
## Read in times as "chron" class. Requires chron 2.3-22 or later.[在“历代志下”#读取。要求时线2.3-22或更高版本。]
z <- read.zoo("foo.csv", header = TRUE, sep = ",", FUN = as.chron)

## same but with custom format.  Note as.chron uses POSIXt-style [#相同,但使用自定义格式。注意as.chron使用POSIXt式]
## Read in times as "chron" class. Requires chron 2.3-24 or later.[在“历代志下”#读取。要求时线2.3-24或更高版本。]
z <- read.zoo("foo.csv", header = TRUE, sep = ",", FUN = as.chron,
        format = "

## same file format but read it in times as "POSIXct" class.[#相同的文件格式,但阅读倍“POSIXct”类。]
z <- read.zoo("foo.csv", header = TRUE, sep = ",", tz = "")

## csv file with first column mm-dd-yyyy. Read times as "Date" class.[#csv文件,第一列MM-DD-YYYY。 “日期”类的读取时间。]
z <- read.zoo("foo.csv", header = TRUE, sep = ",", format = "%m-%d-%Y")

## whitespace separated file with first column of form YYYY-mm-ddTHH:MM:SS[#空格分隔的文件与第一列形式YYYY-MM-DDTHH:MM:SS]
## and no headers.  T appears literally.  Requires chron 2.3-22 or later.[#不带标题。从字面上显示T。要求时线2.3-22或更高版本。]
z <- read.zoo("foo.csv", FUN = as.chron)

# We use "NULL" in colClasses for those columns we don't need but in [在colClasses那些我们不需要的列,但在我们使用“NULL”]
# col.names we still have to include dummy names for them.  Of what [col.names我们还必须包括虚拟名称。是什么]
# is left the index is the first three columns (1:3) which we convert [离开索引的第一个列(1:3),我们将]
# to chron class times in FUN and then truncate to 5 seconds in FUN2.  [历代志上上课时间FUN,并,然后截断至5秒FUN2。]
# Finally we use aggregate = mean to average over the 5 second intervals.[最后,我们使用,合计=平均平均超过5秒的时间间隔。]
library("chron")

Lines <- "CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 300 0
CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 40 51 73.25 100 0
CVX 20070201 9 40 52 73.25 100 0
CVX 20070201 9 40 53 73.25 300 0"

z <- read.zoo(textConnection(Lines),
        colClasses = c("NULL", "NULL", "numeric", "numeric", "numeric", "numeric",
                "numeric", "NULL"),
        col.names = c("Symbol", "Date", "Hour", "Minute", "Second", "Price",
                "Volume", "junk"),
        index = 1:3,  # do not count columns that are "NULL" in colClasses[不计列,“NULL”colClasses]
        FUN = function(h, m, s) times(paste(h, m, s, sep = ":")),
        FUN2 = function(tt) trunc(tt, "00:00:05"),
        aggregate = mean)

## omit the read.table() phase and directly supply a data.frame[#省略了read.table()阶段,直接提供数据框]
dat <- data.frame(date = paste("2000-01-", 10:15, sep = ""), a = rnorm(6), b = 1:6)
z <- read.zoo(dat)

## using built-in data frame BOD[#使用内置的数据框BOD]
read.zoo(BOD)

read.zoo(BOD, FUN = as.Date)

read.zoo(BOD[c(1:6, 1), ], aggregate = mean)

\dontrun{
# read in all csv files in the current directory and merge them[阅读所有CSV文件在当前目录中,并把它们合并]
read.zoo(Sys.glob("*.csv"), header = TRUE, sep = ",")
}


## End(Not run)[#(不执行)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-24 01:44 , Processed in 0.022691 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表