识别 NA 部分的开始和结束项
假设我在 R
中有一些数据,如下所示:
c(0.11, NA, NA, NA, 2.76, 3.65, NA, NA, NA, NA, 1.56)
How might I effective extract the start and end term of every "block" of NA
value?如果结果是一个数据框,我希望它看起来像这样:
first.na last.na
1 2 4
2 7 10
我正在尝试训练自己以避免 for
循环,因为我将在非常大的数据集上执行此类操作(按 1e9 项的顺序),并且 na.omit
不太有帮助。
Let's say I have some data in R
that looks like this:
c(0.11, NA, NA, NA, 2.76, 3.65, NA, NA, NA, NA, 1.56)
How might I efficiently extract the start and end terms of each "block" of NA
values? If the result were a data frame, I would want it to look something like this:
first.na last.na
1 2 4
2 7 10
I'm trying to train myself to avoid for
loops since I'll be doing this type of operation on very large datasets (on the order of 1e9 terms), and na.omit
isn't quite helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许有一个函数可以完成这项工作,但你可以这样做:
Maybe there is a function to do that work, but you can do by: