[R] count appearence of zero in a vector

arun smartpink111 at yahoo.com
Fri Jan 4 01:38:16 CET 2013


Hi,
YOu could use ?count() from library(plyr) or ?table() or ?sum()

count(test)[,2][count(test)[,1]==0]
#[1] 6
table(test)["0"]
#0 
#6 
A.K.




----- Original Message -----
From: Hermann Norpois <hnorpois at googlemail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, January 3, 2013 5:49 PM
Subject: [R] count appearence of zero in a vector

Hello,

I wish to count how often zero (0) appears in the vector test.

test
[1] 1 1 1 1 1 1 2 1 1 1 0 2 0 1 1 0 0 0 1 1 1 0 1 2 1 1 1 1 1 1


I think of something like ...

> sapply (test, function (x) if (x==0 ...

... but actually I dont know how to carry on.

Could anybody give me a hint?

Thanks Hermann

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list