m is the matrix you are working with. this creates a vector, wntg (means you have to go) that lists columns that have a number of numbers of NA values ββgreater than 500
The terms of this comparison can be easily changed to suit your needs.
Then create a new matrix that I call mr (means abbreviation m), where you removed the columns defined by the vector, wntg
In this simple example, I made the case when you want to exclude columns with more than two NA
wntg <-What (colSums (is.na (m))> 2)
MR <-m [, - with (wntg)]
> m<-matrix(c(1,2,3,4,NA,NA,7,8,9,NA,NA,NA), nrow=4, ncol =3) > m [,1] [,2] [,3] [1,] 1 NA 9 [2,] 2 NA NA [3,] 3 7 NA [4,] 4 8 NA > wntg<-which(colSums(is.na(m))>2) > wntg [1] 3 > mr<-m[,-c(wntg)] > mr [,1] [,2] [1,] 1 NA [2,] 2 NA [3,] 3 7 [4,] 4 8