File: bit_sort_unique.Rd

package info (click to toggle)
r-cran-bit 4.0.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 996 kB
  • sloc: ansic: 5,083; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (2)
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bitsort.R
\name{bit_sort_unique}
\alias{bit_sort_unique}
\title{bit sort unique}
\usage{
bit_sort_unique(
  x,
  decreasing = FALSE,
  na.last = NA,
  has.dup = TRUE,
  range_na = NULL
)
}
\arguments{
\item{x}{an integer vector}

\item{decreasing}{\code{FALSE} (ascending) or \code{TRUE} (descending)}

\item{na.last}{\code{NA} removes NAs, \code{FALSE} puts NAs at the beginning, \code{TRUE} puts NAs at the end}

\item{has.dup}{TRUE (the default) assumes that \code{x} might have duplicates, set to \code{FALSE} if duplicates are impossible}

\item{range_na}{\code{NULL} calls \code{\link{range_na}}, optionally the result of \code{\link{range_na}} can be given here to avoid calling it again}
}
\value{
a sorted unique integer vector
}
\description{
fast combination of \code{\link{sort}} and \code{\link{unique}} for integers
}
\details{
determines the range of the integers and checks if the density justifies use 
of a bit vector; if yes, creates the result using a bit vector; if no, falls back to \code{sort(unique())}
}
\examples{
bit_sort_unique(c(2L,1L,NA,NA,1L,2L))
bit_sort_unique(c(2L,1L,NA,NA,1L,2L), na.last=FALSE)
bit_sort_unique(c(2L,1L,NA,NA,1L,2L), na.last=TRUE)
bit_sort_unique(c(2L,1L,NA,NA,1L,2L), decreasing = TRUE)
bit_sort_unique(c(2L,1L,NA,NA,1L,2L), decreasing = TRUE, na.last=FALSE)
bit_sort_unique(c(2L,1L,NA,NA,1L,2L), decreasing = TRUE, na.last=TRUE)

\dontrun{
x <- sample(1e7, replace=TRUE)
system.time(bit_sort_unique(x))
system.time(sort(unique(x)))
x <- sample(1e7)
system.time(bit_sort_unique(x))
system.time(sort(x))
} 
}
\seealso{
\code{\link{sort}}, \code{\link{unique}}, 
  \code{\link{bit_sort}}, \code{\link{bit_unique}}
}