本文介绍了如何找到向量中缺失值的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R语言必须具有什么功能才能找到数据框中的缺失值,或者至少如何知道该数据框具有缺失值?

What features does the R language have to find missing values in dataframe or at least, how to know that the dataframe has missing values?

推荐答案

x = matrix(rep(c(NA, 1,NA), 3), ncol=3, nrow=3)
print(x)
     [,1] [,2] [,3]
[1,]   NA   NA   NA
[2,]    1    1    1
[3,]   NA   NA   NA

布尔值矩阵:是值NA

matrix of boolean values: is the value NA

is.na(x)
      [,1]  [,2]  [,3]
[1,]  TRUE  TRUE  TRUE
[2,] FALSE FALSE FALSE
[3,]  TRUE  TRUE  TRUE

NA值指标:

which(is.na(x), arr.ind = T)
     row col
[1,]   1   1
[2,]   3   1
[3,]   1   2
[4,]   3   2
[5,]   1   3
[6,]   3   3

查看矩阵是否缺少任何值:

see if the matrix has any missing values:

any(is.na(x))
TRUE

这篇关于如何找到向量中缺失值的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 01:03