2019-01-12
阅读量:
1664
使用is.na()函数
> is.na(leadership[,6:10])
q1 q2 q3 q4 q5
[1,] FALSE FALSE FALSE FALSE FALSE
[2,] FALSE FALSE FALSE FALSE FALSE
[3,] FALSE FALSE FALSE FALSE FALSE
[4,] FALSE FALSE FALSE TRUE TRUE
[5,] FALSE FALSE FALSE FALSE FALSE
这里的leadership[,6:10]将数据框限定到第6列至第10列,接下来is.na()识别出了缺
失值。
当你在处理缺失值的时候,你要一直记得两件重要的事情。第一,缺失值被认为是不可比较
的,即便是与缺失值自身的比较。这意味着无法使用比较运算符来检测缺失值是否存在。例如,
逻辑测试myvar == NA的结果永远不会为TRUE。作为替代,你只能使用处理缺失值的函数(如
本节中所述的那些)来识别出R数据对象中的缺失值。
第二, R 并不把无限的或者不可能出现的数值标记成缺失值。再次地,这和其余像SAS之类
类似的程序处理这类数值的方式所不同。正无穷和负无穷分别用Inf和–Inf所标记。因此5/0返
回Inf。不可能的值(比如说, sin(Inf))用NaN符号来标记(not a number,不是一个数)。若
要识别这些数值,你需要用到is.infinite()或is.nan()。






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论