[R] Counting zeros in a matrix

Richard M. Heiberger rmh at temple.edu
Tue Nov 28 22:39:48 CET 2006


A <- matrix(c(
1,1,1,1,0,1,1,1,1,
1,1,1,0,1,0,1,0,0,
1,0,1,0,0,1,0,0,0,
1,1,0,0,0,0,1,0,0),
4, 9, byrow=TRUE)

apply(A, 1, function(x) sum(diff(x)==1))



More information about the R-help mailing list