Histogram-like counting.

histc(x, edges)

Arguments

x

numeric vector or matrix.

edges

numeric vector of grid points, must be monotonically non-decreasing.

Details

n = histc(x,edges) counts the number of values in vector x that fall between the elements in the edges vector (which must contain monotonically nondecreasing values). n is a length(edges) vector containing these counts.

If x is a matrix then cnt and bin are matrices too, and

for (j in (1:n)) cnt[k,j] <- sum(bin[, j] == k)

Value

returns a list with components cnt and bin. n(k) counts the number of values in x that lie between edges(k) <= x(i) < edges(k+1). The last counts any values of x that match edges(n). Values outside the values in edges are not counted. Use -Inf and Inf in edges to include all values.

bin[i] returns k if edges(k) <= x(i) < edges(k+1), and 0 if x[i] lies outside the grid.

See also

Examples