[R] counting missing values
Torsten Hothorn
Torsten.Hothorn at rzmail.uni-erlangen.de
Thu Jun 5 16:37:23 CEST 2003
> 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...
Torsten
> 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
>
>
>
>
> *************************************************************************
> Ce message et toutes les pieces jointes (ci-apres le "message") sont
> confidentiels et etablis a l'intention exclusive de ses destinataires.
> Toute utilisation ou diffusion non autorisee est interdite.
> Tout message electronique est susceptible d'alteration.
> La SOCIETE GENERALE et ses filiales declinent toute responsabilite au
> titre de ce message s'il a ete altere, deforme ou falsifie.
> ********
> This message and any attachments (the "message") are confidentia... {{dropped}}
>
> ______________________________________________
> 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