删除具有nan值的行 [英] remove row with nan value
本文介绍了删除具有nan值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有以下数据:
data <- c(1,2,3,4,5,6,NaN,5,9,NaN,23,9)
attr(data,"dim") <- c(6,2)
data
[,1] [,2]
[1,] 1 NaN
[2,] 2 5
[3,] 3 9
[4,] 4 NaN
[5,] 5 23
[6,] 6 9
现在,我想删除其中包含NaN值的行:第1行和第4行. 但是我不知道这些行在哪里,如果它是一个包含100.000+行的数据集,那么我需要用一个函数找到它们并删除完整的行.
Now i want to remove the rows with the NaN values in it: row 1 and 4. But i don't know where these rows are, if it's a dataset of 100.000+ rows, so i need to find them with a function and remove the complete row.
有人能指出我正确的方向吗?
Can anybody point me in the right direction?
推荐答案
函数complete.cases
会告诉您所需行的位置:
The function complete.cases
will tell you where the rows are that you need:
data <- matrix(c(1,2,3,4,5,6,NaN,5,9,NaN,23,9), ncol=2)
data[complete.cases(data), ]
[,1] [,2]
[1,] 2 5
[2,] 3 9
[3,] 5 23
[4,] 6 9
这篇关于删除具有nan值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文