Hi,

Brandon Invergo wrote:
You can use the length() and which() functions for that:

 > length(which(m == 2))
Or even shorter since TRUE Values have a value of 1

mymatrix <- matrix(sample(x=1:10, size=1000, replace=TRUE), ncol=5)
sum(mymatrix==2)
length(which(mymatrix==2)) #should give the same result

Best,
Roland

______________________________________________
R-help@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.

Reply via email to