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

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

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

                                        Last Observation Carried Forward
                                         最后观察结转

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

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

Generic function for replacing each NA with the most recent non-NA prior to it.
取代每个NA与最近的非-NA在它之前的通用函数。


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


na.locf(object, na.rm = TRUE, ...)
## Default S3 method:[默认方法]
na.locf(object, na.rm = TRUE, fromLast, rev,
        maxgap = Inf, rule = 2, ...)



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

参数:object
an object.
一个对象。


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


参数:fromLast
logical. Causes observations to be carried backward rather than forward.  Default is FALSE. With a value of TRUE this corresponds to NOCB  (next observation carried backward). It is not supported if x or xout is specified.  
逻辑。原因观测值进行倒退而不是前进。默认是FALSE。值TRUE此相对应的NOCB(下观察向后)。如果x或xout指定不支持。


参数:rev
Use fromLast instead.  This argument will be eliminated in the future in favor of fromLast.
使用fromLast“。在未来的fromLast赞成,该参数将被淘汰。


参数:maxgap
Runs of more than maxgap  NAs are retained, other NAs are removed and the last occurrence in the resulting series prior to each time point in xout is used as that time point's output value. (If xout is not specified this reduces to retaining runs of more than maxgap NAs  while filling other NAs with the last occurrence of a non-NA.)  
运行超过maxgapNA的保留,其他NAS被删除,由此带来的一系列xout每个时间点前的最后一次出现在作为,时间点的输出值。 (如果xout不指定,这样可以减少保持运行的多maxgapNA的,却使其他NA的最后一次出现的非NA )。


参数:rule
See approx.
见approx。


参数:...
further arguments passed to methods.
进一步的参数传递给方法。


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

An object in which each NA in the input object is replaced by the most recent non-NA prior to it.  If there are no earlier non-NAs then  the NA is omitted (if na.rm = TRUE) or it is not replaced (if na.rm = FALSE).  
每个NA在输入对象,其中的一个目的是由最近的非-NA到它之前取代。如果有不早不NAS,然后NA省略(如果na.rm = TRUE)或不更换(如果na.rm = FALSE)。

The arguments x and xout can be used in which case they have the same meaning as in approx.
的参数x和xout可以使用,在这种情况下,他们在approx具有相同涵义。

Note that if a multi-column zoo object has a column entirely composed of NA then with na.rm = TRUE, the default, the above implies that the resulting object will have zero rows. Use na.rm = FALSE to preserve the NA values instead.
需要注意的是,如果多列式动物园对象中有一列完全由NA然后用na.rm = TRUE,在默认情况下,意味着生成的对象将具有零行。使用na.rm = FALSE保存NA值而不是。


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

zoo
zoo


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


az <- zoo(1:6)

bz <- zoo(c(2,NA,1,4,5,2))
na.locf(bz)
na.locf(bz, fromLast = TRUE)

cz <- zoo(c(NA,9,3,2,3,2))
na.locf(cz)

# generate and fill in missing dates[生成并填写缺少的日期]
z <- zoo(c(0.007306621, 0.007659046, 0.007681013,
        0.007817548, 0.007847579, 0.007867313),
        as.Date(c("1993-01-01", "1993-01-09", "1993-01-16",
        "1993-01-23", "1993-01-30", "1993-02-06")))
g <- seq(start(z), end(z), "day")
na.locf(z, xout = g)

# similar but use a 2 second grid[类似的,但使用2秒的网格]

z <- zoo(1:9, as.POSIXct(c("2010-01-04 09:30:02", "2010-01-04 09:30:06",
"2010-01-04 09:30:07", "2010-01-04 09:30:08", "2010-01-04 09:30:09",
"2010-01-04 09:30:10", "2010-01-04 09:30:11", "2010-01-04 09:30:13",
"2010-01-04 09:30:14")))

g <- seq(start(z), end(z), by = "2 sec")
na.locf(z, xout = g)

## get 5th of every month or most recent date prior to 5th if 5th missing.[#每月或最近日至5日之前五5日失踪。]
## Result has index of the date actually used.[#结果之日起实际使用的索引。]

z <- zoo(c(1311.56, 1309.04, 1295.5, 1296.6, 1286.57, 1288.12,
1289.12, 1289.12, 1285.33, 1307.65, 1309.93, 1311.46, 1311.28,
1308.11, 1301.74, 1305.41, 1309.72, 1310.61, 1305.19, 1313.21,
1307.85, 1312.25, 1325.76), as.Date(c(13242, 13244,
13245, 13248, 13249, 13250, 13251, 13252, 13255, 13256, 13257,
13258, 13259, 13262, 13263, 13264, 13265, 13266, 13269, 13270,
13271, 13272, 13274)))

# z.na is same as z but with missing days added (with NAs)[z.na是为z相同,但与失踪的日子里(与NAS)]
# It is formed by merging z with a zero with series having all the dates.[它是由合并z的一个零系列的所有日期。]

rng <- range(time(z))
z.na <- merge(z, zoo(, seq(rng[1], rng[2], by = "day")))

# use na.locf to bring values forward picking off 5th of month[使用na.locf带来价值,向前摘5月]
na.locf(z.na)[as.POSIXlt(time(z.na))$mday == 5]

## this is the same as the last one except instead of always using the[#这是作为最后一个除外,而不是始终使用相同]
## 5th of month in the result we show the date actually used[第5个月的结果,我们实际使用的日期]

# idx has NAs wherever z.na does but has 1, 2, 3, ... instead of[idx的有定居随时随地z.na,但有1,2,3,...而不是]
# z.na's data values (so idx can be used for indexing)[z.na的数据值(因此可用于索引idx的)]

idx <- coredata(na.locf(seq_along(z.na) + (0 * z.na)))

# pick off those elements of z.na that correspond to 5th[这些元素对应的z.na,到第5]

z.na[idx[as.POSIXlt(time(z.na))$mday == 5]]

## only fill single-day gaps[,#只填写单日的差距]

merge(z.na, filled1 = na.locf(z.na, maxgap = 1))

## fill NAs in first column by inflating the most recent non-NA[#NAS在第一列填写最近的非-NA膨胀]
## by the growth in second column.  Note that elements of x-x[在第二列#的增长。请注意,x-x的元素]
## are NA if the corresponding element of x is NA and zero else[#不适用如果相应元素的x是NA和零其他]

m <- zoo(cbind(c(1, 2, NA, NA, 5, NA, NA), seq(7)^2), as.Date(1:7))

r <- na.locf(m[,1]) * m[,2] / na.locf(m[,2] + (m[,1]-m[,1]))
cbind(V1 = r, V2 = m[,2])

## repeat a quarterly value every month[#每月重复的季度值]
## preserving NAs[#保存来港定居]
zq <- zoo(c(1, NA, 3, 4), as.yearqtr(2000) + 0:3/4)
tt <- as.yearmon(start(zq)) + seq(0, len = 3 * length(zq))/12
na.locf(zq, xout = tt, maxgap = 0)



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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-23 22:49 , Processed in 0.021368 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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