File: binCounts.Rd

package info (click to toggle)
r-cran-matrixstats 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,104 kB
  • sloc: ansic: 7,300; sh: 11; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,953 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/binCounts.R
\name{binCounts}
\alias{binCounts}
\title{Fast element counting in non-overlapping bins}
\usage{
binCounts(x, idxs = NULL, bx, right = FALSE, ...)
}
\arguments{
\item{x}{A \code{\link[base]{numeric}} \code{\link[base]{vector}} of K
positions for to be binned and counted.}

\item{idxs}{A \code{\link[base]{vector}} indicating subset of elements to
operate over. If \code{\link[base]{NULL}}, no subsetting is done.}

\item{bx}{A \code{\link[base]{numeric}} \code{\link[base]{vector}} of B + 1
ordered positions specifying the B > 0 bins \code{[bx[1], bx[2])},
\code{[bx[2], bx[3])}, ..., \code{[bx[B], bx[B + 1])}.}

\item{right}{If \code{\link[base:logical]{TRUE}}, the bins are right-closed
(left open), otherwise left-closed (right open).}

\item{...}{Not used.}
}
\value{
Returns an \code{\link[base]{integer}} \code{\link[base]{vector}} of
length B with non-negative integers.
}
\description{
Counts the number of elements in non-overlapping bins
}
\details{
\code{binCounts(x, bx, right = TRUE)} gives equivalent results as
\code{rev(binCounts(-x, bx = rev(-bx), right = FALSE))}, but is faster
and more memory efficient.
}
\section{Missing and non-finite values}{

Missing values in \code{x} are ignored/dropped.  Missing values in \code{bx}
are not allowed and gives an error.
}

\seealso{
An alternative for counting occurrences within bins is
\code{\link[graphics]{hist}}, e.g. \code{hist(x, breaks = bx,
plot = FALSE)$counts}.  That approach is ~30-60\% slower than
\code{binCounts(..., right = TRUE)}.

To count occurrences of indices \code{x} (positive
\code{\link[base]{integer}}s) in \code{[1, B]}, use \code{tabulate(x,
nbins = B)}, where \code{x} does \emph{not} have to be sorted first.  For
details, see \code{\link[base]{tabulate}}().

To average values within bins, see \code{\link{binMeans}}().
}
\author{
Henrik Bengtsson
}
\keyword{univar}