remove row with nan value

后端 未结 2 432
悲哀的现实
悲哀的现实 2020-12-13 18:56

let\'s say, for example, i have this data:

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条回答
  •  别那么骄傲
    2020-12-13 19:30

    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
    

提交回复
热议问题