[R] Deleting columns from a matrix
d.rizopoulos at erasmusmc.nl
Sun May 24 19:22:56 CEST 2009
one way is:
ind <- colSums(is.na(mat)) != nrow(mat)
I hope it helps.
> I have a matrix given by the code:
> mat <-
> This is a 10x5 matrix containing missing values. All columns except the
> second contain missing values. I want to delete all columns that contain
> ALL missing values, and in this case, it would be the first and fourth
> columns. Any column that has at least one real number would remain. I know
> I can use "mat[,-1]" to delete the first column, but I have a much larger
> matrix where it is impossible to tell how many columns contain all missing
> values and which don't.
> Is there a function or something else that may be able to help me accomplish
> Thanks in advance.
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
More information about the R-help