R: [R] extracting columns with NA's
Vito Muggeo
vito.muggeo at giustizia.it
Fri Sep 19 12:39:21 CEST 2003
If I have understood what you mean, you can use the (surely non-optimal)
code:
#build a matrix ....
A<-matrix(1:20,nrow=5)
A[2,4]<-NA
A[,3]<-rep(NA,nrow(A))
#count the missing value in each column
fi<-apply(A,2,function(x)sum(is.na(x)))
#exclude column(s) having a number of NA equal to nrow(A). Of course you can
modify the "==" as well as "nrow(A)"
A1<-A[!which(fi==nrow(A)),]
Hope this help you
best,
vito
----- Original Message -----
From: antonio rodriguez <arv at ono.com>
To: R-help <r-help at stat.math.ethz.ch>
Sent: Friday, September 19, 2003 11:58 AM
Subject: [R] extracting columns with NA's
> 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
More information about the R-help
mailing list