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

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

[复制链接]
发表于 2012-2-17 09:53:54 | 显示全部楼层 |阅读模式
as.Date(base)
as.Date()所属R语言包:base

                                        Date Conversion Functions to and from Character
                                         日期转换函数和从字符

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

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

Functions to convert between character representations and objects of class "Date" representing calendar dates.
字符类"Date"表示日历日期的陈述和对象之间的转换功能。


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


as.Date(x, ...)
## S3 method for class 'character'
as.Date(x, format = "", ...)
## S3 method for class 'numeric'
as.Date(x, origin, ...)
## S3 method for class 'POSIXct'
as.Date(x, tz = "UTC", ...)

## S3 method for class 'Date'
format(x, ...)

## S3 method for class 'Date'
as.character(x, ...)



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

参数:x
An object to be converted.
要转换的对象。


参数:format
A character string.  If not specified, it will try "%Y-%m-%d" then "%Y/%m/%d" on the first non-NA element, and give an error if neither works.
一个字符串。如果没有指定,它会尝试"%Y-%m-%d"然后"%Y/%m/%d"上的第一个非NA元素,并给予如果既不作品的错误。


参数:origin
a Date object, or something which can be coerced by as.Date(origin, ...) to such an object.
Date对象,或者东西可以强制as.Date(origin, ...)这样一个对象。


参数:tz
a timezone name.
一个时区的名称。


参数:...
Further arguments to be passed from or to other methods, including format for as.character and as.Date methods.
进一步或以其他方法传递的参数,包括formatas.character和as.Date方法。


Details

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

The usual vector re-cycling rules are applied to x and format so the answer will be of length that of the longer of the vectors.
通常的矢量循环再用的规则适用于x和format所以答案是长度的向量。

Locale-specific conversions to and from character strings are used where appropriate and available.  This affects the names of the days and months.
酌情提供使用区域设置特定的转换和字符串。这会影响到日,月的名字。

The as.Date methods accept character strings, factors, logical NA and objects of classes "POSIXlt" and "POSIXct".  (The last is converted to days by ignoring the time after midnight in the representation of the time in specified timezone, default UTC.)  Also objects of class "date" (from package date) and "dates" (from package chron).  Character strings are processed as far as necessary for the format specified: any trailing characters are ignored.
as.Date方法接受字符串,影响因素,逻辑NA类"POSIXlt"和"POSIXct"对象。 (最后转换为天由忽略午夜后的时间,在指定的时区,缺省的UTC时间表示。)"date"(包date)和"dates"的类对象(包chron)。字符串处理,尽可能为指定格式的必要:任何尾随的字符将被忽略。

as.Date will accept numeric data (the number of days since an epoch), but only if origin is supplied.
as.Date会接受数字数据(天以来划时代的数量),但只有当origin提供。

The format and as.character methods ignore any fractional part of the date.
format和as.character方法忽略任何小数部分的日期。


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

The format and as.character methods return a character vector representing the date.  NA dates are returned as NA_character_.
format和as.character方法返回一个表示日期的特征向量。返回NANA_character_日期。

The as.Date methods return an object of class "Date".
as.Date方法返回一个对象类"Date"。


从其他系统转换----------Conversion from other Systems----------

Most systems record dates internally as the number of days since some origin, but this is fraught with problems, including
国内大多数系统记录日期为天数,因为有些起源,但是这是很多问题,包括

Is the origin day 0 or day 1?  As the "Examples" show, Excel manages to use both choices for its two date systems.
为原点0天或1天?作为“例子”节目,Excel的管理使用两种日期系统两种选择。

If the origin is far enough back, the designers may show their ignorance of calendar systems.  For example, Excel's designer thought 1900 was a leap year (claiming to copy the error from earlier DOS spreadsheets), and Matlab's designer chose the non-existent date of "January 0, 0000" (there is no such day), not specifying the calendar.  (There is such a year in the "Gregorian" calendar as used in ISO 8601:2004, but that does say that it is only to be used for years before 1582 with the agreement of the parties in information exchange.)
如果是远远不够回原籍,设计师可以展示自己的日历系统的无知。例如,Excel的设计师认为1900是闰年(自称拷贝从早期的DOS电子表格中的错误),和Matlab的设计师选择的,“一月0,0000不存在的日期(有没有这样的一天),不指定日历。 (有这样的“公历”日历年在ISO 8601:2004,但并说这是只用于前1582多年,与各方信息交流的协议。)

The only safe procedure is to check the other systems values for known dates: reports on the Internet (including R-help) are more often wrong than right.
唯一安全的程序是检查其他系统已知的日期值:在互联网上的报告(包括R-HELP)往往比对错误。


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

The default formats follow the rules of the ISO 8601 international standard which expresses a day as "2001-02-03".
默认的格式遵循ISO 8601国际标准,表示为"2001-02-03"每天的规则。

If the date string does not specify the date completely, the returned answer may be system-specific.  The most common behaviour is to assume that a missing year, month or day is the current one.  If it specifies a date incorrectly, reliable implementations will give an error and the date is reported as NA.  Unfortunately some common implementations (such as glibc) are unreliable and guess at the intended meaning.
如果日期字符串不完全指定日期,返回的答案可能是系统特定的。最常见的行为是假设失踪一年,一个月或一天是当前的一个。如果它指定的日期不正确,可靠的实现将给出一个错误,日期为NA报道。不幸的是,一些常见的实现(如glibc)是不可靠的和猜测的本意。

Years before 1CE (aka 1AD) will probably not be handled correctly.
1CE(又名1AD)前几年将可能不会被正确处理。


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

...) ISO 8601. Data elements and interchange formats – Information interchange – Representation of dates and times. For links to versions available on-line see (at the time of writing) http://www.qsl.net/g1smd/isopdf.htm; for information on the current official version, see http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html.

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

Date for details of the date class; locales to query or set a locale.
日期类的详细信息,日期;locales来查询或设置一个区域。

Your system's help pages on strftime and strptime to see how to specify their formats.  Windows users will find no help page for strptime: code based on glibc is used (with corrections), so all the format specifiers described here are supported, but with no alternative number representation nor era available in any locale.
系统的帮助页面上strftime和strptime来看看如何指定其格式。 Windows用户会发现strptime没有帮助页面:代码的基础上glibc(更正),说明这里所描述的所有格式都支持,但没有其他的数字表示,也没有在任何可用的时代语言环境。


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


## locale-specific version of the date[#语言环境的特定版本的日期]
format(Sys.Date(), "%a %b %d")

## read in date info in format 'ddmmmyyyy'[#日期格式“ddmmmyyyy”信息阅读]
## This will give NA(s) in some locales; setting the C locale[#这将给在某些语言环境中NA(S);设置C语言环境]
## as in the commented lines will overcome this on most systems.[#注释行,将克服在大多数系统上。]
## lct &lt;- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")[#LCT < -  Sys.getlocale(“LC_TIME的”); Sys.setlocale(“LC_TIME的”,“C”类)]
x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
z <- as.Date(x, "%d%b%Y")
## Sys.setlocale("LC_TIME", lct)[#Sys.setlocale(“LC_TIME的”,LCT)]
z

## read in date/time info in format 'm/d/y'[#读取日期/时间信息格式“M / D / Y]
dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
as.Date(dates, "%m/%d/%y")

## date given as number of days since 1900-01-01 (a date in 1989)[#日期1900-01-01(日期在1989年以来的天数)]
as.Date(32768, origin="1900-01-01")
## Excel is said to use 1900-01-01 as day 1 (Windows default) or[#Excel的使用1900-01-01 1天(Windows默认)或]
## 1904-01-01 as day 0 (Mac default), but this is complicated by Excel[#1904年1月1日为第0天(Mac的默认),但是这是复杂的Excel中]
## treating 1900 as a leap year.[#治疗1900年为闰年。]
## So for dates (post-1901) from Windows Excel[#所以从Windows Excel中的日期(后-1901)]
as.Date(35981, origin="1899-12-30") # 1998-07-05[1998年7月5日]
## and Mac Excel[#和Excel中的Mac]
as.Date(34519, origin="1904-01-01") # 1998-07-05[1998年7月5日]
## (these values come from http://support.microsoft.com/kb/214330)[#(这些值来http://support.microsoft.com/kb/214330)]

## Experiment shows that Matlab's origin is 719529 days before ours,[#实验结果表明,Matlab的起源七一九五二九天前我们是,]
## so Matlab day 734373 can be imported as[MATLAB一天734373#可以进口]
as.Date(734373, origin = "1970-01-01") - 719529
## (value from http://www.mathworks.com/help/techdoc/matlab_prog/bspgcx2-1.html)[#(从http://www.mathworks.com/help/techdoc/matlab_prog/bspgcx2-1.html的价值)]

## Timezone effect[#时区的影响]
z &lt;- ISOdate(2010, 04, 13, c(0,12)) # midnight and midday UTC[午夜和正午UTC]
as.Date(z) # in UTC[在UTC]
## these timezone names are common[#这些时区名称是常见的]
as.Date(z, tz ="NZ")
as.Date(z, tz ="HST") # Hawaii[夏威夷]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 03:17 , Processed in 0.019106 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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