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

R语言:DateTimeClasses()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 10:08:34 | 显示全部楼层 |阅读模式
DateTimeClasses(base)
DateTimeClasses()所属R语言包:base

                                        Date-Time Classes
                                         日期时间类

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

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

Description of the classes "POSIXlt" and "POSIXct" representing calendar dates and times (to the nearest second).
类描述"POSIXlt"和"POSIXct"代表日历日期和时间(精确到秒)。


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


## S3 method for class 'POSIXct'
print(x, ...)

## S3 method for class 'POSIXct'
summary(object, digits = 15, ...)

time + z
z + time
time - z
time1 lop time2



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

参数:x, object
An object to be printed or summarized from one of the date-time classes.
要打印一个对象或日期时间类的总结。


参数:digits
Number of significant digits for the computations: should be high enough to represent the least important time unit exactly.
计算有效位数的号码:应该高到足以完全代表了最重要的时间单位。


参数:...
Further arguments to be passed from or to other methods.
进一步的参数被传递或其他方法。


参数:time
date-time objects
日期时间对象


参数:time1, time2
date-time objects or character vectors.  (Character vectors are converted by as.POSIXct.)
日期时间对象或特征向量。 (字符向量转换as.POSIXct。)


参数:z
a numeric vector (in seconds)
数字向量(以秒为单位)


参数:lop
One of ==, !=, <, <=, > or >=.
一个==,!=,<,<=,>或>=。


Details

详情----------Details----------

There are two basic classes of date/times.  Class "POSIXct" represents the (signed) number of seconds since the beginning of 1970 (in the UTC timezone) as a numeric vector.  Class "POSIXlt" is a named list of vectors representing
有两个基本的日期/时间类。 "POSIXct"类代表自1970年作为一个数字矢量(UTC时区)开始秒(签名)数量。 "POSIXlt"类的代表向量命名名单




sec 0&ndash;61: seconds
sec0-61:秒




min 0&ndash;59: minutes
min0-59分钟




hour 0&ndash;23: hours
hour0-23小时




mday 1&ndash;31: day of the month
mday1-31月的一天




mon 0&ndash;11: months after the first of the year.
mon0-11个月后,今年第一。




year years since 1900.
year年自1900年以来。




wday 0&ndash;6 day of the week, starting on Sunday.
wday0-6日的一周,上周日开始。




yday 0&ndash;365: day of the year.
yday0-365:一天的一年。




isdst Daylight Savings Time flag.  Positive if in
isdst夏令时标志。正面的,如果在

Note that the internal list structure is somewhat hidden, as many methods, including print() or str, apply to the abstract date-time vector, as for "POSIXct". The classes correspond to the POSIX/C99 constructs of "calendar time" (the time_t data type) and "local time" (or broken-down time, the struct tm data type), from which they also inherit their names.  The components of "POSIXlt" are integer vectors, except sec.
请注意,有些隐藏内部列表结构,尽可能多的方法,包括print()或str,适用于抽象的日期,时间向量作为"POSIXct",。类对应的日历时间(time_t数据类型)和“本地时间”(或故障停机时间,struct tm数据类型)POSIX/C99结构,从他们还继承他们的名字。 "POSIXlt"组件是整数向量,除了sec。

"POSIXct" is more convenient for including in data frames, and "POSIXlt" is closer to human-readable forms.  A virtual class "POSIXt" exists from which both of the classes inherit: it is used to allow operations such as subtraction to mix the two classes. Note that length(x) is the length of the corresponding (abstract) date/time vector, also in the "POSIXlt" case.
"POSIXct"更方便,包括在数据框和"POSIXlt"是人类可读的形式。虚拟类"POSIXt"存在的类都继承:它是用来让如减法运算混合使用这两个类。注意length(x)(摘要)相应的日期/时间向量的长度,在"POSIXlt"的情况下也。

Components wday and yday of "POSIXlt" are for information, and are not used in the conversion to calendar time. However, isdst is needed to distinguish times at the end of DST: typically 1am to 2am occurs twice, first in DST and then in standard time.  At all other times isdst can be deduced from the first six values, but the behaviour if it is set incorrectly is platform-dependent.  
组件wday和yday"POSIXlt"信息,而不是在转换使用日历时间。然而,isdst需要区分在DST结束时间:通常凌晨凌晨发生两次,首次在DST,然后在标准时间。在所有其他时间isdst可以从上半年值推导,但如果设置不当的行为是依赖于平台。

Logical comparisons and limited arithmetic are available for both classes.  One can add or subtract a number of seconds from a date-time object, but not add two date-time objects.  Subtraction of two date-time objects is equivalent to using difftime.  Be aware that "POSIXlt" objects will be interpreted as being in the current timezone for these operations, unless a timezone has been specified.
逻辑比较和算术有限的可用这两个类。一个可以添加或减去的秒数从一个日期时间对象,但不能添加两个日期时间的对象。减法两个日期时间对象是相当于使用difftime。要知道,"POSIXlt"对象将被解释作为当前时区为这些操作中,除非已指定一个时区。

"POSIXlt" objects will often have an attribute "tzone", a character vector of length 3 giving the timezone name from the TZ environment variable and the names of the base timezone and the alternate (daylight-saving) timezone.  Sometimes this may just be of length one, giving the timezone name.
"POSIXlt"对象往往有一个属性"tzone",长度为3的特征向量,TZ环境变量和基地时区的名称和备用(夏令时区名称)的时区。有时,这可能只是一个长度,给人的时区名称。

"POSIXct" objects may also have an attribute "tzone", a character vector of length one.  If set to a non-empty value, it will determine how the object is converted to class "POSIXlt" and in particular how it is printed.  This is usually desirable, but if you want to specify an object in a particular timezone but to be printed in the current timezone you may want to remove the "tzone" attribute (e.g. by c(x)).
"POSIXct"对象也可能有一个属性"tzone",特征向量的长度为一。如果设置为一个非空值,这将决定如何转换类"POSIXlt"“,特别是如何被打印的对象。这通常是可取的,但如果你想在一个特定的时区指定的对象,但在当前的时区印,你可能想删除(例如"tzone")c(x)属性。

Unfortunately, the conversion is complicated by the operation of time zones and leap seconds (24 days have been 86401 seconds long so far: the times of the extra seconds are in the object .leap.seconds). The details of this are entrusted to the OS services where possible. This always covers the period 1970&ndash;2037, and on most machines back to 1902 (when time zones were in their infancy).  Outside the platform limits we use our own C code.  This uses the offset from GMT in use either for 1902 (when there was no DST) or that predicted for one of 2030 to 2037 (chosen so that the likely DST transition days are Sundays), and uses the alternate (daylight-saving) timezone only if isdst is positive or (if -1) if DST was predicted to be in operation in the 2030s on that day.  (There is no reason to suppose that the DST rules will remain the same in the future, and indeed the US legislated in 2005 to change its rules as from 2007, with a possible future reversion.)
不幸的是,转换复杂的操作时区和闰秒(24天已经长86401秒迄今额外秒钟的时间,对象是.leap.seconds)。这个细节是委托给操作系统的服务,在可能的情况下。这个总占地面积2070至37年期间,在大多数机器上,到1902年(时区处于起步阶段)。以外的平台限制,我们用自己的C代码。使用抵消从GMT(时有没有DST)在使用1902或预测2030年至2037年(选择可能DST过渡天是星期日),并使用备用(夏令时)时区只有isdst是正面或(如果-1)如果dst预计在当天的2030操作。 (假设DST规则将在未来保持相同的,的确,美国在2005年立法,以改变它的规则,从2007年与未来可能出现逆转,没有理由。)

It seems that some rare systems use leap seconds, but most ignore them (as required by POSIX).  This is detected and corrected for at build time, so all "POSIXct" times used by R do not include leap seconds. (Conceivably this could be wrong if the system has changed since build time, just possibly by changing locales or the "zoneinfo" database.)
看来,一些罕见的系统使用闰秒,但大多忽略他们(如POSIX)。这是通过检测和纠正在编译的时候,因此所有"POSIXct"由R使用次数不包括闰秒。 (相信这可能是错误的,如果该系统已自编译的时候改变,只是可能改变语言环境或zoneinfo数据库。)

Using c on "POSIXlt" objects converts them to the current time zone, and on "POSIXct" objects drops any "tzone" attributes (even if they are all marked with the same time zone).
使用c"POSIXlt"对象转换他们目前的时区,滴"POSIXct"对象任何"tzone"的属性(即使它们都具有相同的时区标记) 。

A few times have specific issues.  First, the leap seconds are ignored, and real times such as "2005-12-31 23:59:60" are (probably) treated as the next second.  However, they will never be generated by R, and are unlikely to arise as input.  Second, on some OSes there is a problem in the POSIX/C99 standard with "1969-12-31 23:59:59 UTC", which is -1 in calendar time and that value is on those OSes also used as an error code.  Thus as.POSIXct("1969-12-31   23:59:59", format = "%Y-%m-%d %H:%M:%S", tz = "UTC") may give NA, and hence as.POSIXct("1969-12-31 23:59:59",   tz = "UTC") will give "1969-12-31 23:59:00".  Other OSes (including the code used by R on Windows) report errors separately and so are able to handle that time as valid.
有几次,有具体问题。首先,闰秒将被忽略,和真正的时间,如"2005-12-31 23:59:60"(可能)作为未来的第二个处理。然而,他们将永远不会产生由R,是不可能出现的输入。其次,在一些操作系统有一个问题"1969-12-31 23:59:59 UTC"POSIX/C99标准,这是在日历时间和价值-1操作系统也作为一个错误代码。因此as.POSIXct("1969-12-31   23:59:59", format = "%Y-%m-%d %H:%M:%S", tz = "UTC")可能会给NA,因此as.POSIXct("1969-12-31 23:59:59",   tz = "UTC")会"1969-12-31 23:59:00"。其他操作系统(包括在Windows上使用的R代码)报告错误分开,所以能够为有效处理时间。

The print methods respect options("max.print").
打印方法方面options("max.print")。


亚秒精度----------Sub-second Accuracy----------

Classes "POSIXct" and  "POSIXlt" are able to express fractions of a second.  (Conversion of fractions between the two forms may not be exact, but will have better than microsecond accuracy.)
类"POSIXct"和"POSIXlt"能够表达的第二个分数。 (分数两种形式之间的转换可能不准确,但将有优于微秒精度。)

Fractional seconds are printed only if options("digits.secs") is set: see strftime.
秒的小数部分options("digits.secs")只有印是集:看到strftime。


警告----------Warning----------

Some Unix-like systems (especially Linux ones) do not have environment variable TZ set, yet have internal code that expects it (as does POSIX).  We have tried to work around this, but if you get unexpected results try setting TZ.  See Sys.timezone for valid settings.
一些类Unix系统(特别是Linux)不具备环境变量TZ集,但有内部的代码,预计它(如POSIX的)。我们曾试图解决这个问题,但如果你得到意想不到的结果尝试设置TZ。有效设置Sys.timezone。


参考文献----------References----------

1/2, 8&ndash;11. http://www.r-project.org/doc/Rnews/Rnews_2001-2.pdf

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

Dates for dates without times.
没有时间日期的日期。

as.POSIXct and as.POSIXlt for conversion between the classes.
as.POSIXct和as.POSIXlt类之间的转换。

strptime for conversion to and from character representations.
strptime转换和字符表示。

Sys.time for clock time as a "POSIXct" object.
Sys.time时钟时间"POSIXct"对象。

difftime for time intervals.
difftime时间间隔。

cut.POSIXt, seq.POSIXt, round.POSIXt and trunc.POSIXt for methods for these classes.
cut.POSIXt,seq.POSIXt,round.POSIXt和trunc.POSIXt这些类的方法。

weekdays for convenience extraction functions.
weekdays为了方便提取功能。


举例----------Examples----------


(z &lt;- Sys.time())             # the current date, as class "POSIXct"[当前的日期,作为类“POSIXct”]

Sys.time() - 3600             # an hour ago[一个小时前]

as.POSIXlt(Sys.time(), "GMT") # the current time in GMT[目前在GMT时间]
format(.leap.seconds)         # all 24 leap seconds in your timezone[您的时区中的所有24个闰秒]
print(.leap.seconds, tz="PST8PDT")  # and in Seattle's[在西雅图]

## look at *internal* representation of "POSIXlt" :[#看看*内部*“POSIXlt”的表示:]
leapS <- as.POSIXlt(.leap.seconds)
names(leapS) ; is.list(leapS)
utils::str(unclass(leapS), vec.len = 7)

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 00:04 , Processed in 0.077829 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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