powered by
countzeros used in the base function 'apply', or 'tapply' to count the number of zeros in a vector
countzeros(invect)
vector of values
A single value of zero or the number of zeros
# NOT RUN { x <- matrix(trunc(runif(20)*10),nrow=4,ncol=5) print(x) apply(x,1,countzeros) # count by rows apply(x,2,countzeros) # count by columns # }
Run the code above in your browser using DataLab