删除 xts 中的 NA 列 [英] Removing NA columns in xts

查看:32
本文介绍了删除 xts 中的 NA 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的 xts

I have an xts in the following format

                   a        b     c        d       e        f   ......
2011-01-03         11.40    NA    23.12    0.23    123.11   NA  ......
2011-01-04         11.49    NA    23.15    1.11    111.11   NA  ......
2011-01-05         NA       NA    23.11    1.23    142.32   NA  ......
2011-01-06         11.64    NA    39.01    NA      124.21   NA  ......
2011-01-07         13.84    NA    12.12    1.53    152.12   NA  ......

有没有我可以应用的函数来生成一个新的 xts 或 data.frame 缺少只包含 NA 的列?

Is there a function I can apply to generate a new xts or data.frame missing the columns containing only NA?

带有 NA 的列的位置不是静态的,因此无法按名称或位置删除这些列

The position of the columns with the NAs isn't static so just removing those columns by name or position isn't possible

推荐答案

Supose DF is your data.frame

Supose DF is your data.frame

 DF [, -which(sapply(DF, function(x) sum(is.na(x)))==nrow(DF))]
               a     c    d      e
2011-01-03 11.40 23.12 0.23 123.11
2011-01-04 11.49 23.15 1.11 111.11
2011-01-05    NA 23.11 1.23 142.32
2011-01-06 11.64 39.01   NA 124.21
2011-01-07 13.84 12.12 1.53 152.12

这篇关于删除 xts 中的 NA 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆