I am trying to remove the rows of a matrix in R. My criteria for row removal is that the column contains at least one NA
(note that the entire row does not need to be NA
like in other questions on this site).
For example, if matrix A looks like the following
32 54 34
NA 10 NA
17 93 NA
Only the first row should remain.
This is what I am trying, but I am getting a column instead of a row.
newMatrix <- A[,rowSums(apply(A, 1, is.na))<1]
#A is a matrix
What am I missing? I tried doing !is.na
, but R didn't like that.
question from:
https://stackoverflow.com/questions/65939424/removing-rows-of-a-matrix-with-at-least-one-na-in-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…