R API reference
Every public function of the kwker R package, for vectors and data frames, with its parameters and results (Kwker 0.1.0).
kwk_sort Page
kwk_sort(x, decreasing = FALSE, na.last = NA)
Returns a sorted copy of a numeric vector, like base::sort.
Arguments
x: a double or integer vector.decreasing: TRUE sorts largest first.na.last: NA (the default) drops NAs; TRUE puts them last, FALSE first.
Returns
The sorted vector.
Example
kwk_sort(c(3, 1, 2)) # 1 2 3
Notes
- Ties as base::sort keeps them: -0 with 0, NA with NaN, in input order.
kwk_order Page
kwk_order(x, decreasing = FALSE)
Returns the positions (1-based) that sort a numeric vector, like order(x). Equal values keep their input order.
Arguments
x: a double or integer vector.decreasing: TRUE orders largest first.
Returns
An integer vector of positions; NAs come last.
Example
kwk_order(c(30, 10, 20)) # 2 3 1
kwk_topk Page
kwk_topk(x, k, decreasing = FALSE)
Returns the k smallest (or largest) values in order, with their positions.
Arguments
x: a double or integer vector.k: how many values.decreasing: TRUE returns the k largest.
Returns
List(values, indices); indices are 1-based, equal values go to the earlier position first, NAs last.
Example
kwk_topk(c(12, 7, 30, 18), 2, decreasing = TRUE) # values 30 18, indices 3 4
kwk_isa Page
kwk_isa()
The engine in use: "avx512", "avx2" or "portable".
kwk_version Page
kwk_version()
The C library's version.
kwk_order_df Page
kwk_order_df(df, by = names(df), decreasing = FALSE, threads = 1L)
Returns the row order (1-based) that sorts a data frame by one or more key columns, like order(df$a, df$b, ..., method = "radix").
Arguments
df: a data frame (or a list of equal-length columns).by: the key columns, names or positions, most significant first.decreasing: TRUE / FALSE per key column (recycled).threads: the number of threads.
Returns
An integer vector of row positions; NAs last, ties in row order.
Example
df <- data.frame(city = c(2, 1, 2), age = c(30, 40, 20))
kwk_order_df(df, by = c("city", "age"), decreasing = c(FALSE, TRUE)) # 2 1 3
Notes
- Key columns: integer, double (also Date, POSIXct), logical, factor (by code) or character (byte order).
kwk_sort_df Page
kwk_sort_df(df, by = names(df), decreasing = FALSE, threads = 1L)
Returns a data frame's rows sorted by key columns: df[kwk_order_df(df, by, decreasing), , drop = FALSE].
Arguments
df: a data frame.by: the key columns, names or positions, most significant first.decreasing: TRUE / FALSE per key column (recycled).threads: the number of threads.
Returns
The sorted data frame.
kwk_topk_df Page
kwk_topk_df(df, k, by = names(df), decreasing = FALSE)
Returns the first k rows of a data frame in key order without sorting all rows, like SQL ORDER BY ... LIMIT k.
Arguments
df: a data frame.k: how many rows.by: the key columns, names or positions, most significant first.decreasing: TRUE / FALSE per key column (recycled).
Returns
A data frame of up to k rows.