I have a matrix mat
whose elements are NA
, 0
, 1
, 2
. I got an answer about removing the columns with 0 or NA or both values but now I want to add additional condition for deleting the columns.
I have to delete the columns which contain the same value, delete the columns with NA or 0 or both, the columns with NA or 1 or both and the column with NA or 2 or both (I should keep the columns which have variation in their values)
I used this code but didn't work properly:
mat_nonNA <- mat[, !apply((is.na(mat) | mat == 0) & (is.na(mat) |
mat==1) &(is.na(mat) | mat==2), 2, all)]