[R] counting missing values

2003-06-06 Thread vincent . stoliaroff
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




*
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}}

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


Re: [R] counting missing values

2003-06-06 Thread Uwe Ligges
[EMAIL PROTECTED] 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

Uwe Ligges

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


Re: [R] counting missing values

2003-06-06 Thread Torsten Hothorn
 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}}

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



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


RE: [R] counting missing values

2003-06-06 Thread Hotz, T.
Dear Vincent

 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

Does

my.matrix-cbind(c(0,1,NA),c(NA,1,NA))
count.NA-function(the.matrix){
  result-t(apply(the.matrix,1,function(x,n){
m-sum(is.na(x))
c(m,m/n)
  },n=dim(the.matrix)[2]))
  dimnames(result)-list(dimnames(the.matrix)[[1]],c(row count,proportion))
  result
}
count.NA(my.matrix)

do what you were looking for? Hope that helps.

Cheers

Thomas

---

Thomas Hotz
Research Associate in Medical Statistics
University of Leicester
United Kingdom

Department of Epidemiology and Public Health
22-28 Princess Road West
Leicester
LE1 6TP
Tel +44 116 252-5410
Fax +44 116 252-5423

Division of Medicine for the Elderly
Department of Medicine
The Glenfield Hospital
Leicester
LE3 9QP
Tel +44 116 256-3643
Fax +44 116 232-2976

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


Re: [R] counting missing values

2003-06-06 Thread Peter Dalgaard BSA
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


Re: [R] counting missing values

2003-06-06 Thread Thomas Lumley
On Thu, 5 Jun 2003, Uwe Ligges wrote:

 [EMAIL PROTECTED] 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


and

   rowMeans(is.na(Matrix))*100

should be faster

-thomas

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


RE: [R] counting missing values

2003-06-05 Thread Liaw, Andy
 From: Uwe Ligges [mailto:[EMAIL PROTECTED]
 
 [EMAIL PROTECTED] 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
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

--
Notice: This e-mail message, together with any attachments, cont... {{dropped}}

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