[R] Counter
Philipp Pagel
p.pagel at wzw.tum.de
Thu Jul 23 12:59:30 CEST 2009
On Thu, Jul 23, 2009 at 10:44:16AM +0000, amor Gandhi wrote:
> Hi everyone,
>
> Is there any counter function in R for the following purpose:
> x <- matrix(c(1,1,0,2,1,0,0,2,0,1,2,1,2,1,0,1),nrow=4)
> As I would like to know how many zeros, ones, and twos in each row of x?
Yes there is:
As you are interested int he counts by row you can use apply:
apply(x, 1, table)
cu
Philipp
--
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/
More information about the R-help
mailing list