[.xts(xts)
[.xts()所属R语言包:xts
Extract Subsets of xts Objects
提取XTS对象的子集
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Details on efficient subsetting of xts objects for maximum performance and compatibility.
有效的子集xts对象最高的性能和兼容性的详细信息。
用法----------Usage----------
## S3 method for class 'xts'
x[i, j, drop = FALSE, which.i=FALSE, ...]
参数----------Arguments----------
参数:x
xts object
XTS对象
参数:i
the rows to extract. Numeric, timeBased or ISO-8601 style (see details)
行提取。数字,基于时间或ISO-8601型(见详情)
参数:j
the columns to extract, numeric or by name
列提取,数字或名称
参数:drop
should dimension be dropped, if possible
尺寸被丢弃,如果可能的话
参数:which.i
return the "i" values used for subsetting. No subset will be performed.
返回的“i”的值用于子集。无子集将被执行。
参数:...
additional arguments (unused)
额外的参数(未使用)
Details
详细信息----------Details----------
One of the primary motivations, and key points of differentiation of the time series class xts, is the ability to subset rows by specifying ISO-8601 compatible range strings. This allows for natural range-based time queries without requiring prior knowledge of the underlying time object used in construction.
的主要动机,而分化的时间序列类XTS的关键点之一,是通过指定ISO-8601兼容的范围字符串的子集行的能力。这样就可以自然的范围内基于时间的查询,而不需要事先了解的基础对象,用于建设。
When a raw character vector is used for the i subset argument, it is processed as if it was ISO-8601 compliant. This means that it is parsed from left to right, according to the following specification:
当原始特征向量的i的子集参数,它是处理,如果它是ISO-8601标准。这意味着,它解析从左到右,根据以下说明书:
CCYYMMDD HH:MM:SS.ss+
CCYYMMDD HH:MM:SS.SS +
A full description will be expanded from a left-specified truncated one.
一个完整的描述将扩大从左边指定截断的。
Additionally, one may specify range-based queries by simply supplying two time descriptions seperated by a forward slash:
此外,人们可以简单地提供一个正斜杠分隔的两个时间说明指定范围的查询:
CCYYMMDD HH:MM:SS.ss+/CCYYMMDD HH:MM:SS.ss
CCYYMMDD HH:MM:SS.SS + / CCYYMMDD HH:MM:SS.SS
The algorithm to parse the above is .parseISO8601 from the xts package.
上述分析的算法是.parseISO8601xts包。
ISO-style subsetting, given a range type query, makes use of a custom binary search mechanism that allows for very fast subsetting as no linear search though the index is required. ISO-style character vectors may be longer than length one, allowing for multiple non-contiguous ranges to be selected in one subsetting call.
ISO风格的子集,给出了一系列类型的查询,使用一个自定义的二进制搜索机制,允许非常快的子集,因为没有线性搜索,但该指数。 ISO风格特征向量可能是更长的时间长度为一比,允许多个不连续的范围中选择一个子集调用。
If a character vector representing time is used in place of numeric values, ISO-style queries, or timeBased objects, the above parsing will be carried out on each element of the i-vector. This overhead can be very costly. If the character approach is used when no ISO range querying is needed, it is recommended to wrap the "i" character vector with the I() function call, to allow for more efficient internal processing. Alternately converting character vectors to POSIXct objects will provide the most performance efficiency.
如果一个字符矢量表示时间的场所中使用的数值,ISO样式的查询,或基于时间的对象,将进行上述的解析的i矢量的每个元素上。此开销可能会非常昂贵。如果没有ISO范围查询时,使用的八字方针是必要的,建议包我的字符向量I()函数调用,以便更有效的内部处理。或者特征向量转换POSIXct对象,将提供最大的性能效益。
As xts uses POSIXct time representations of all user-level index classes internally, the fastest timeBased subsetting will always be from POSIXct objects, regardless of the indexClass of the original object. All non-POSIXct time classes are converted to character first to preserve consistent TZ behavior.
xts使用POSIXct的时间表示所有用户级指标类的内部,速度最快的基于时间的子集将始终是从POSIXct的对象,不管indexClass原始对象的。所有的非POSIXct时间类被转换为字符首先保持一致的TZ行为。
值----------Value----------
An extraction of the original xts object. If which.i is TRUE, the corresponding integer "i" values used to subset will be returned.
的提取原始XTS对象。如果which.i是TRUE,对应的整数的“i”值的子集将被退回。
(作者)----------Author(s)----------
Jeffrey A. Ryan
参考文献----------References----------
Information interchange - Representation of dates and time http://www.iso.org
参见----------See Also----------
xts, .parseISO8601,
xts,.parseISO8601,
实例----------Examples----------
x <- xts(1:1000, as.Date("2000-01-01")+1:1000)
y <- xts(1:1000, as.POSIXct(format(as.Date("2000-01-01")+1:1000)))
x.subset <- index(x)[1:20]
x[x.subset] # by original index type[原来的索引类型]
system.time(x[x.subset])
x[as.character(x.subset)] # by character string. Beware![字符的字符串。当心!]
system.time(x[as.character(x.subset)]) # slow![慢!]
system.time(x[I(as.character(x.subset))]) # wrapped with I(), faster![I()包裹着,速度更快!]
x['200001'] # January 2000[2000年1月]
x['1999/2000'] # All of 2000 (note there is no need to use the exact start)[2000年(注意,是没有必要使用的确切的开始)]
x['1999/200001'] # January 2000 [2000年1月]
x['2000/200005'] # 2000-01 to 2000-05[2000-01至2000-05]
x['2000/2000-04-01'] # through April 01, 2000[通过2000年4月1日]
y['2000/2000-04-01'] # through April 01, 2000 (using POSIXct series)[通过2000年4月1日(使用POSIXct系列)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|