[R] counting missing values
Liaw, Andy
andy_liaw at merck.com
Fri Jun 6 03:54:19 CEST 2003
> From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de]
>
> vincent.stoliaroff at socgen.com wrote:
>
> > 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
> >
> > it takes a lot of time to run with a 1000 rows matrix
> >
> > I'd like to know if there is a function already implemented
> to count the
> > number of occurence of a given values in a vector
> >
> >
> > For information,
> > here is the function
> > count<-0
> > for (i in 1:nrow(Matrix))
> > {
> > for (j in 1:ncol(Matrix)) {if (is.na(Matrix[i,j]))
> count<-count+1}
> > Result[i,1]<-((count/(ncol(Matrix)))*100);
> > count<-0
> > }
> > Result
> >
> > thanks for any help
> > Vincent
>
> Well, it's pretty easy to do it:
>
> apply(Matrix, 1, function(x) sum(is.na(x))) / ncol(Matrix) * 100
Or perhaps faster:
rowMeans(is.na(Matrix)) * 100
Andy
> Uwe Ligges
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, cont... {{dropped}}
More information about the R-help
mailing list