ÎÒдÁËÒ»¸öÀý×Ó£º
> mat = matrix(1:18,ncol=3)
> mat[c(1,4),1] = NA
> mat[3,2] = NA
> mat[c(2,5),3] = NA
> mat
[,1] [,2] [,3]
[1,] NA 7 13
[2,] 2 8 NA
[3,] 3 NA 15
[4,] NA 10 16
[5,] 5 11 NA
[6,] 6 12 18
>
> # remove the rows with NA in the first columns
> mat[!is.na(mat[,1]),]
[,1] [,2] [,3]
[1,] 2 8 NA
[2,] 3 NA 15
[3,] 5 11 NA
[4,] 6 12 18
>
> # remove the rows with NA in any column
> mat[!is.na(mat[,1])&!is.na(mat[,2])&!is.na(mat[,3]),]
[1] 6 12 18
|