Torsten Hothorn <[EMAIL PROTECTED]> writes:

> > Hello R lovers
> > I have written a little cute function to count the number of missing value
> > per row in a matrix and return the percentage of missing value
> >
> 
> R> M <- matrix(rnorm(25), ncol=5)
> R> diag(M) <- NA
> R> M[2,3] <- NA
> R> apply(M, 2, function(x) sum(is.na(x)))/ncol(M)
> [1] 0.2 0.2 0.4 0.2 0.2
> 
> the percentage of missing values per row...

Or:

> apply(is.na(M), 2, mean)
[1] 0.2 0.2 0.4 0.2 0.2

(Actually, that's the proportions. ...*100 for percentages)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to