找回密码
 注册
查看: 5079|回复: 1

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

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

                                        Replace NA by Interpolation
                                         通过插值替换NA

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

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

Generic functions for replacing each NA with interpolated values.
为更换每一个NA的插补值的通用功能。


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


na.approx(object, ...)
## S3 method for class 'zoo'
na.approx(object, x = index(object), xout, ..., na.rm = TRUE, along)
## S3 method for class 'zooreg'
na.approx(object, ...)
## S3 method for class 'ts'
na.approx(object, ...)
## Default S3 method:[默认方法]
na.approx(object, x = index(object), xout, ..., na.rm = TRUE, maxgap = Inf, along)

na.spline(object, ...)
## S3 method for class 'zoo'
na.spline(object, x = index(object), xout, ..., na.rm = TRUE, along)
## S3 method for class 'zooreg'
na.spline(object, ...)
## S3 method for class 'ts'
na.spline(object, ...)
## Default S3 method:[默认方法]
na.spline(object, x = index(object), xout, ..., na.rm = TRUE, maxgap = Inf, along)




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

参数:object
object in which NAs are to be replaced
对象,其中NAs是要更换


参数:x, xout
Variables to be used for interpolation as in approx.
变量用于插在approx。


参数:na.rm
logical. Should leading NAs be removed?
逻辑。如果领导NA的被删除?


参数:maxgap
maximum number of consecutive NAs to fill. Any longer gaps will be left unchanged. Note that all methods listed above can accept maxgap as it is ultimately passed to the  default method.
连续NA的最大数量来填补。任何更长的差距将保持不变。需要注意的是上面列出的所有方法可以接受maxgap,因为它是最终传递给default方法。


参数:along
deprecated.
过时了。


参数:...
further arguments passed to methods. The n argument of approx is currently not supported.
进一步的参数传递给方法。 n参数approx,目前不支持。


Details

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

Missing values (NAs) are replaced by linear interpolation via approx or cubic spline interpolation via spline, respectively.  
遗漏值(NAS)所取代approx,分别通过spline或三次样条插值通过线性插值。

It can also be used for series disaggregation by specifying xout.
它也可以被用于系列通过指定xout,解聚。

By default the index associated with object is used for interpolation. Note, that if this calls index.default this gives an equidistant spacing 1:NROW(object). If object is a matrix or data.frame, the interpolation is done separately for each column.
默认情况下,指数与object插补时使用。请注意,如果这就要求index.default这给出了一个等距间隔1:NROW(object)。如果object是一个矩阵或数据框,内插是分别为每个列。

If obj is a plain vector then na.approx(obj, x, y, xout, ...) returns approx(x = x[!na], y = coredata(obj)[!na], xout = xout, ...) (where na indicates observations with NA) such that xout defaults to x.
obj如果是一个普通的矢量na.approx(obj, x, y, xout, ...)回报approx(x = x[!na], y = coredata(obj)[!na], xout = xout, ...)(其中naNA)等表示的意见,xout默认<X >。

If obj is a zoo, zooreg or ts object its coredata value is processed as described and its time index is xout if specified and index(obj) otherwise. If obj is two dimensional then the above is applied to each column separately. For examples, see below.
如果obj是一个zoo,zooreg或ts对象coredata这个值描述的方式处理xout如果指定时间指数和index(obj)否则。如果obj是二维那么上面的被施加到每一列分开。有关示例,请参阅下文。

If obj has more than one column, the above strategy is applied to each column.
如果obj具有一个以上的列,在上述策略应用于每一列。


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

An object of similar structure as object with (internal) NAs replaced by interpolation. Leading or trailing NAs are omitted if na.rm = TRUE or not replaced if na.rm = FALSE.
类似的结构object的对象(内部)NA的S通过插值替换。前导或尾随NA如果s的省略,na.rm = TRUE或不更换的话na.rm = FALSE。


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

zoo, approx, na.contiguous, na.locf, na.omit, na.trim, spline, stinterp
zoo,approx,na.contiguous,na.locf,na.omit,na.trim,spline,stinterp


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



z <- zoo(c(2, NA, 1, 4, 5, 2), c(1, 3, 4, 6, 7, 8))

## use underlying time scale for interpolation[#使用基本的时间尺度内插]
na.approx(z)
## use equidistant spacing[#使用等距间隔]
na.approx(z, 1:6)

# with and without na.rm = FALSE[带和不带na.rm = FALSE]
zz <- c(NA, 9, 3, NA, 3, 2)
na.approx(zz, na.rm = FALSE)
na.approx(zz)

d0 <- as.Date("2000-01-01")
z <- zoo(c(11, NA, 13, NA, 15, NA), d0 + 1:6)

# NA fill, drop or keep leading/trailing NAs[,NA填写,下降或保持领先/后港定居]
na.approx(z)
na.approx(z, na.rm = FALSE)

# extrapolate to point outside of range of time points[外推到一点时间点的范围之外]
# (a) drop NA, (b) keep NA, (c) extrapolate using rule = 2 from approx()[(一)降NA,(b)保持NA,(三)推断出从约(第2条)]
na.approx(z, xout = d0 + 7)
na.approx(z, xout = d0 + 7, na.rm = FALSE)
na.approx(z, xout = d0 + 7, rule = 2)

# use splines - extrapolation handled differently[使用花键 - 外推不同的处理方式]
z <- zoo(c(11, NA, 13, NA, 15, NA), d0 + 1:6)
na.spline(z)
na.spline(z, na.rm = FALSE)
na.spline(z, xout = d0 + 1:6)
na.spline(z, xout = d0 + 2:5)
na.spline(z, xout = d0 + 7)
na.spline(z, xout = d0 + 7, na.rm = FALSE)

## using na.approx for disaggregation[#使用na.approx分解]
zy <- zoo(1:3,  2000:2001)

# yearly to monthly series[每年每月的系列]
zmo <- na.approx(zy, xout = as.yearmon(2000+0:13/12))
zmo

# monthly to daily series[每月每天系列]
sq <- seq(as.Date(start(zmo)), as.Date(end(zmo), frac = 1), by = "day")
zd <- na.approx(zmo, x = as.Date, xout = sq)
head(zd)

# weekly to daily series[每周每天系列]
zww <- zoo(1:3, as.Date("2001-01-01") + seq(0, length = 3, by = 7))
zww
zdd <- na.approx(zww, xout = seq(start(zww), end(zww), by = "day"))
zdd

# The lines do not show up because of the NAs[线没有显示出来,因为在NAS]
plot(cbind(z, z), type = "b", screen = 1)
# use na.approx to force lines to appear[使用na.approx力线出现]
plot(cbind(z, na.approx(z)), type = "b", screen = 1)

# Workaround where less than 2 NAs can appear in a column[解决方法小于2,NAS可以出现在一列]
za <- zoo(cbind(1:5, NA, c(1:3, NA, 5), NA)); za

ix <- colSums(!is.na(za)) > 0
za[, ix] <- na.approx(za[, ix]); za

# using na.approx to create regularly spaced series[使用na.approx创建规则排列的系列]
# z has points at 10, 20 and 40 minutes while output also has a point at 30[z具有10,20和40分钟的点,而输出,也有一个在30点]
if(require("chron")) {
  tt <- as.chron("2000-01-01 10:00:00") + c(1, 2, 4) * as.numeric(times("00:10:00"))
  z <- zoo(1:3, tt)
  tseq <- seq(start(z), end(z), by = times("00:10:00"))
  na.approx(z, xout = tseq)
}

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


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

使用道具 举报

发表于 2013-1-18 22:12:10 | 显示全部楼层
这个帖子,很好啊~~挺好的e~~帮了忙~~
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-24 02:29 , Processed in 0.025460 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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