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

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

[复制链接]
发表于 2012-2-16 22:01:23 | 显示全部楼层 |阅读模式
as.POSIXlt(base)
as.POSIXlt()所属R语言包:base

                                        Date-time Conversion Functions
                                         日期时间转换功能

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

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

Functions to manipulate objects of classes "POSIXlt" and "POSIXct" representing calendar dates and times.
函数来操纵类的对象"POSIXlt"和"POSIXct"代表日历日期和时间。


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


as.POSIXct(x, tz = "", ...)
as.POSIXlt(x, tz = "", ...)

## S3 method for class 'character'
as.POSIXlt(x, tz = "", format, ...)

## S3 method for class 'numeric'
as.POSIXlt(x, tz = "", origin, ...)

## S3 method for class 'POSIXlt'
as.double(x, ...)



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

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


参数:tz
A timezone specification to be used for the conversion, if one is required.  System-specific (see time zones), but "" is the current timezone, and "GMT" is UTC (Universal Time, Coordinated).
一个时区,必须使用特定的转换,如果需要的话。特定的系统(见时区),但""是当前的时区,"GMT"是UTC(通用时间协调)。


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


参数:format
character string giving a date-time format as used by strptime.
日期时间格式字符串由strptime使用。


参数:origin
a date-time object, or something which can be coerced by as.POSIXct(tz="GMT") to such an object.
日期时间对象,或一些可以强制as.POSIXct(tz="GMT")这样一个对象。


Details

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

The as.POSIX* functions convert an object to one of the two classes used to represent date/times (calendar dates plus time to the nearest second).  They can convert a wide variety of objects, including objects of the other class and of classes "Date", "date" (from package date), "chron" and "dates" (from package chron) to these classes.  Dates without times are treated as being at midnight UTC.
as.POSIX*功能转换为对象用来表示日期/时间(日历日期加时间精确到秒)的两个班之一。他们可以转换的对象广泛,包括各种其他类和对象类"Date","date"(包date)"chron"和"dates" (包的chron)这些类。没有时间日期将被视为在午夜UTC。

They can also convert character strings of the formats "2001-02-03" and "2001/02/03" optionally followed by white space and a time in the format "14:52" or "14:52:03".  (Formats such as "01/02/03" are ambiguous but can be converted via a format specification by strptime.)  Fractional seconds are allowed. Alternatively, format can be specified for character vectors or factors: if it is not specified and no standard format works for all non-NA inputs an error is thrown.
他们还可以转换格式的字符串"2001-02-03"和"2001/02/03"选择白色的空间和时间格式"14:52"或"14:52:03"。 (如格式"01/02/03"含糊不清,但可以通过转换格式规范由strptime。)秒的小数部分是允许的。另外,format可以为指定的字符向量或因素:如果不指定,并没有标准的格式,所有非NA输入一个错误被抛出。

If format is specified, remember that some of the format specifications are locale-specific, and you may need to set the LC_TIME category appropriately via Sys.setlocale.  This most often affects the use of %b, %B (month names) and %p (AM/PM).
如果format指定,请记住,一些特定于语言环境的格式规范,您可能需要通过LC_TIMESys.setlocale类别设置适当。这往往会影响使用%b,%B(月份名)和%p(AM / PM)。

Logical NAs can be converted to either of the classes, but no other logical vectors can be.
逻辑NA的可转换为类之一,但没有其他的逻辑向量。

The as.double method converts "POSIXlt" objects to "POSIXct".
as.double方法"POSIXlt"到"POSIXct"对象转换。

If you are given a numeric time as the number of seconds since an epoch, see the examples.
如果你是一个划时代的秒数的数字时,看到的例子。

Character input is first converted to class "POSIXlt" by strptime: numeric input is first converted to "POSIXct".  Any conversion that needs to go between the two date-time classes requires a timezone: conversion from "POSIXlt" to "POSIXct" will validate times in the selected timezone.  One issue is what happens at transitions to and from DST, for example in the UK
汉字输入先转换为类"POSIXlt"strptime:"POSIXct"先转换成数字输入。任何需要去两个日期时间类之间的转换,需要一个时区转换:从"POSIXlt"将验证"POSIXct"在所选时区的时间。一个问题是发生在从DST的转换,例如,在英国


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

as.POSIXct and as.POSIXlt return an object of the appropriate class.  If tz was specified, as.POSIXlt will give an appropriate "tzone" attribute.  Date-times known to be invalid will be returned as NA.
as.POSIXct和as.POSIXlt返回一个适当的类的对象。如果tz指定as.POSIXlt将给予适当的"tzone"属性。 NA将返回无效的日期时间。


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

Some of the concepts used have to be extended backwards in time (the usage is proleptic).  For example, the origin of time for the "POSIXct" class, "1970-01-01 00:00.00 UTC", is before UTC was defined.  More importantly, conversion is done assuming the Gregorian calendar which was introduced in 1582 and not used universally until the 20th century.  One of the re-interpretations assumed by ISO 8601:2004 is that there was a year zero, even though current year numbering (and zero) is a much later concept (525 AD for year numbers from 1 AD).
时间向后延长(使用率proleptic),所使用的一些概念。例如,"POSIXct"类,1970-01-01 00:00.00联合技术,起源的时间是UTC的定义之前。更重要的是,假设是在1582年推出,并没有普遍使用,直到20世纪的公历转换完成。通过ISO 8601:2004假设重新解释之一是,有一年零,即使本年度编号(零)是晚得多的概念,从公元1年(525年)。

If you want to extract specific aspects of a time (such as the day of the week) just convert it to class "POSIXlt" and extract the relevant component(s) of the list, or if you want a character representation (such as a named day of the week) use format.POSIXlt or format.POSIXct.
如果你要提取时间的特定方面(如星期),只是把它转换类"POSIXlt"的名单中提取相关的组件(S),或者如果你想有一个字符表示(例如)命名为一周中的某一天使用format.POSIXlt或format.POSIXct。

If a timezone is needed and that specified is invalid on your system, what happens is system-specific but attempts to set it will probably be ignored.
如果需要一个时区,指定您的系统上是无效的,会发生什么是特定系统的,但尝试设置它可能会被忽略。


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

DateTimeClasses for details of the classes; strptime for conversion to and from character representations.
类详情DateTimeClasses;strptime转换和字符表示。

Sys.timezone for details of the (system-specific) naming of time zones.
Sys.timezone(系统)命名时区的详细信息。

locales for locale-specific aspects.  
具体语言环境方面的语言环境。


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


(z <- Sys.time())             # the current datetime, as class "POSIXct"[当前DateTime,类“POSIXct”]
unclass(z)                    # a large integer[一个大整数]
floor(unclass(z)/86400)       # the number of days since 1970-01-01 (UTC)[天数自1970-01-01(UTC)]
(z <- as.POSIXlt(Sys.time())) # the current datetime, as class "POSIXlt"[当前DateTime,类“POSIXlt”]
unlist(unclass(z))            # a list shown as a named vector[作为命名的向量显示列表]

## suppose we have a time in seconds since 1960-01-01 00:00:00 GMT[#假设我们有一个在几秒钟的时间自1960年1月1日00:00:00 GMT]
## (the origin used by SAS)[#(由SAS的起源)]
z <- 1472562988
# ways to convert this[如何转换]
as.POSIXct(z, origin="1960-01-01")                # local[当地]
as.POSIXct(z, origin="1960-01-01", tz="GMT")      # in UTC[在UTC]
as.POSIXct(z, origin=ISOdatetime(1960,1,1,0,0,0)) # local[当地]
ISOdatetime(1960,1,1,0,0,0) + z                   # local[当地]

## SPSS dates (R-help 2006-02-16)[SPSS日期(R  - 帮助2006-02-16)]
z <- c(10485849600, 10477641600, 10561104000, 10562745600)
as.Date(as.POSIXct(z, origin="1582-10-14", tz="GMT"))

as.POSIXlt(Sys.time(), "GMT") # the current time in UTC[目前在UTC时间]

## Not run: ## These may not be correct names on your system[#不运行:#这可能不是您的系统上正确的名称]
as.POSIXlt(Sys.time(), "America/New_York")  # in New York[在纽约]
as.POSIXlt(Sys.time(), "EST5EDT")           # alternative.[替代方案。]
as.POSIXlt(Sys.time(), "EST" )   # somewhere in Eastern Canada[在加拿大东部的某处]
as.POSIXlt(Sys.time(), "HST")    # in Hawaii[在夏威夷]
as.POSIXlt(Sys.time(), "Australia/Darwin")

## End(Not run)[#结束(不运行)]

cols <- c("code", "coordinates", "TZ", "comments")
tmp <- read.delim(file.path(R.home("share"), "zoneinfo", "zone.tab"),
                  header = FALSE, comment.char="#", col.names = cols)[“col.names = COLS)]
if(interactive()) View(tmp)

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 10:27 , Processed in 0.027404 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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