[R] counting missing values
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu Jun 5 17:05:04 CEST 2003
Torsten Hothorn <Torsten.Hothorn at rzmail.uni-erlangen.de> 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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list