[R] extracting columns with NA's
Peter Wolf
s-plus at wiwi.uni-bielefeld.de
Fri Sep 19 12:22:51 CEST 2003
antonio rodriguez wrote:
>Hi All,
>
>How do I can delete from a matrix (or array) only those columns which have
>all their values set to NA?
>
>Cheers
>
>Antonio Rodriguez
>---
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
Try:
> x<-matrix(1:16,4,4)
> x[col(x)>=row(x)]<-NA
> x[,! apply(x,2,function(x) all(is.na(x))) ]
[,1] [,2] [,3]
[1,] NA NA NA
[2,] 2 NA NA
[3,] 3 7 NA
[4,] 4 8 12
Peter Wolf
More information about the R-help
mailing list