[R] number of an element in a matrix

Petr PIKAL petr.pikal at precheza.cz
Tue Aug 12 14:09:17 CEST 2008


Hi

r-help-bounces at r-project.org napsal dne 11.08.2008 22:50:08:

> You can use the length() and which() functions for that:
> 
>  > length(which(m == 2))

Or simply

sum(m == 2)
Regards
Petr


> 
> cheers,
> brandon
> 
> 
> rostam shahname wrote:
> > Hi, I wonder if there is any function which gives the number of times 
which
> > an element is repeated in the matrix. Let say there is a matrix, I 
would
> > like to find out how many times number 2 has been repeated in the 
matrix, or
> > in other words, how many elements of the matrix are equal 2.
> > Thanks for your help,
> > Rostam
> >
> >    [[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.
> >
> 
> ______________________________________________
> 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