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

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

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

                                        An Index Class for Monthly Data
                                         月度数据的指数类

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

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

"yearmon" is a class for representing monthly data.
"yearmon"是一类为代表的月度数据。


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


yearmon(x)



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

参数:x
numeric (interpreted as being “in years”).
数字(解释为“年”)。


Details

详细信息----------Details----------

The "yearmon" class is used to represent monthly data. Internally it holds the data as year plus 0 for January, 1/12 for February, 2/12 for March and so on in order that its internal representation is the same as  ts class with frequency = 12. If x is not in this format it is rounded via floor(12*x + .0001)/12.
"yearmon"类是用来表示月度数据。在内部,它拥有的数据加0一月,1/12,2/12,3月等,以便它的内部表示是一样的ts类frequency = 12。如果x是不是这种格式,它是圆形的,通过floor(12*x + .0001)/12。

There are coercion methods available for various classes including: default coercion to "yearmon" (which coerces to "numeric" first) and coercions to and from "yearmon" to "Date" (see below),  "POSIXct", "POSIXlt", "numeric", "character" and "jul".   The last one is from the "tis" package available on CRAN. In the case of as.yearmon.POSIXt the conversion is with respect to GMT.  (Use as.yearmon(format(...)) for other time zones.) In the case of as.yearmon.character the format argument uses the same percent code as  "Date".   These are described in strptime.  Unlike "Date" one can specify a year and month with no day.   Default formats of "%Y-%m", "%Y-%m-%d" and "%b %Y".
有胁迫的方法,可用于各种类别包括:默认情况下强迫"yearmon"("numeric"先)胁迫和强制转换和"yearmon""Date"(见下文), "POSIXct","POSIXlt","numeric","character"和"jul"。最后一个是从"tis"包可在CRAN。在as.yearmon.POSIXt转换的情况下,是相对于GMT。 (使用as.yearmon(format(...))其他时区)的情况下,as.yearmon.characterformat参数使用相同的代码,"Date"%。这些描述strptime。不同"Date"没有一天可以指定年份和月份。默认格式"%Y-%m","%Y-%m-%d"和"%b %Y"。

There is an is.numeric method which returns FALSE.
有一个is.numeric方法返回FALSE。

as.Date.yearmon and as.yearmon.yearqtr  each has an optional second argument of "frac" which is a number between 0 and 1 inclusive that indicates the fraction of the way through the period that the result represents.  The default is 0 which means the beginning of the period.
as.Date.yearmon和as.yearmon.yearqtr“”每个人都有一个可选的第二个参数"frac"这是一个介于0和1之间,表示分数的方式,通过期间的结果表示。默认值是0,这意味着期初。

There is also a date method for as.yearmon usable with objects created with package date.
还有一个dateas.yearmon包date创建的对象使用的方法。

Sys.yearmon() returns the current year/month and methods for min, max and range are defined (by defining  a method for Summary).
Sys.yearmon()返回当前年/月和方法min,max和range的定义(定义一个方法Summary)。

A yearmon mean method is also defined.
Ayearmonmean方法也被定义。


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

Returns its argument converted to class yearmon.
返回其参数转换为类yearmon。


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

yearqtr, zoo, zooreg, ts
yearqtr,zoo,zooreg,ts


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


x <- as.yearmon(2000 + seq(0, 23)/12)
x

as.yearmon("mar07", "%b%y")
as.yearmon("2007-03-01")
as.yearmon("2007-12")

# returned Date is the fraction of the way through[返回的日期部分的方式,通过]
# the period given by frac (= 0 by default)[(= 0默认情况下,通过压裂期间)]
as.Date(x)
as.Date(x, frac = 1)
as.POSIXct(x)

# given a Date, x, return the Date of the next Friday[给定一个日期,X,下周五返回日期]
nextfri <- function(x) 7 * ceiling(as.numeric(x - 1)/7) + as.Date(1)

# given a Date, d, return the same Date in the following month[给定一个日期,D,返回相同的日期在随后的一个月]
# Note that as.Date.yearmon gives first Date of the month.[需要注意的是as.Date.yearmon给出了第一个日期的月份。]
d <- as.Date("2005-1-1") + seq(0,90,30)
next.month <- function(d) as.Date(as.yearmon(d) + 1/12) +
        as.numeric(d - as.Date(as.yearmon(d)))
next.month(d)

# 3rd Friday in last month of the quarter of Date x[在本季度最后一个月的日期X的第三个星期五]
as.Date(as.yearmon(as.yearqtr(x)) + 2/12) + 14

z <- zoo(rnorm(24), x, frequency = 12)
z
as.ts(z)

## convert data fram to multivariate monthly "ts" series[#转换数据FRAM多元每月一次的“TS”系列]
## 1.read raw data[#1.read原始数据]
Lines.raw <- "ID Date Count
123 20 May 1999 1
123 21 May 1999 3
222 1 Feb 2000 2
222 3 Feb 2000 4
"
DF <- read.table(textConnection(Lines.raw), skip = 1,
col.names = c("ID", "d", "b", "Y", "Count"))
## 2. fix raw date[#2。解决原日期]
DF$yearmon <- as.yearmon(paste(DF$b, DF$Y), "%b %Y")
## 3. aggregate counts over months, convert to zoo and merge over IDs[#3。数月的合计数,转换到动物园过的ID和合并]
ag <- function(DF) aggregate(zoo(DF$Count), DF$yearmon, sum)
z <- do.call("merge.zoo", lapply(split(DF, DF$ID), ag))
## 4. convert to "zooreg" and then to "ts"[#4。转换为“zooreg”,再到“TS”]
frequency(z) <- 12
as.ts(z)

xx <- zoo(seq_along(x), x)

## aggregating over year [#同期汇总]
as.year <- function(x) as.numeric(floor(as.yearmon(x)))
aggregate(xx, as.year, mean)


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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-23 21:58 , Processed in 0.027681 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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