Title: | Tools for Cleaning Rectangular Data |
Version: | 1.11.0 |
Description: | A dependency-free collection of simple functions for cleaning rectangular data. This package allows to detect, count and replace values or discard rows/columns using a predicate function. In addition, it provides tools to check conditions and return informative error messages. |
License: | GPL (≥ 3) |
URL: | https://codeberg.org/tesselle/arkhe, https://packages.tesselle.org/arkhe/ |
BugReports: | https://codeberg.org/tesselle/arkhe/issues |
Depends: | R (≥ 3.5) |
Imports: | methods, stats, utils |
Suggests: | tinytest |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2.9000 |
X-schema.org-isPartOf: | https://www.tesselle.org |
X-schema.org-keywords: | data-cleaning, statistics, r-package |
Collate: | 'AllGenerics.R' 'append.R' 'predicates.R' 'assert.R' 'arkhe-deprecated.R' 'arkhe-internal.R' 'arkhe-package.R' 'assign.R' 'clean.R' 'compact.R' 'conditions.R' 'count.R' 'describe.R' 'detect.R' 'discard.R' 'get.R' 'keep.R' 'mathematics.R' 'remove.R' 'replace.R' 'scale.R' 'seek.R' 'sparsity.R' 'statistics.R' 'utilities.R' 'zzz.R' |
NeedsCompilation: | no |
Packaged: | 2025-05-12 15:14:41 UTC; nfrerebeau |
Author: | Nicolas Frerebeau |
Maintainer: | Nicolas Frerebeau <nicolas.frerebeau@u-bordeaux-montaigne.fr> |
Repository: | CRAN |
Date/Publication: | 2025-05-12 17:30:02 UTC |
arkhe: Tools for Cleaning Rectangular Data
Description
A dependency-free collection of simple functions for cleaning rectangular data. This package allows to detect, count and replace values or discard rows/columns using a predicate function. In addition, it provides tools to check conditions and return informative error messages.
Details
Version | 1.11.0 |
License | GPL-3 |
CRAN DOI | doi:10.32614/CRAN.package.arkhe |
Zenodo DOI | doi:10.5281/zenodo.3526659 |
Archéosciences Bordeaux (UMR 6034)
Maison de l'Archéologie
Université Bordeaux Montaigne
F-33607 Pessac cedex
France
Package options
arkhe uses the following options()
to configure behavior:
-
arkhe.verbose
: alogical
scalar. Should R report extra information on progress? Defaults tointeractive()
.
Author(s)
Maintainer: Nicolas Frerebeau nicolas.frerebeau@u-bordeaux-montaigne.fr (ORCID)
Other contributors:
Brice Lebrun (ORCID) (Logo designer) [artist]
Université Bordeaux Montaigne (ROR) [funder]
CNRS (ROR) [funder]
See Also
Useful links:
Report bugs at https://codeberg.org/tesselle/arkhe/issues
Add a (Named) Vector as a Column
Description
Add a (Named) Vector as a Column
Usage
append_column(x, ...)
## S4 method for signature 'data.frame'
append_column(x, column, after = 0, var = ".col")
Arguments
x |
A |
... |
Currently not used. |
column |
A (named) |
after |
An |
var |
A |
Details
If column
is named, names will be matched to the row names of x
. Only
the first match is retained, and elements of column
without a match are
removed. This allows to add as a column a vector whose length is less than
the number of rows in x
(NA
s will be inserted).
Value
A data.frame
.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_rownames()
,
assign()
,
compact()
,
count()
,
detect()
,
discard()
,
get()
,
keep()
,
seek()
Examples
X <- data.frame(
x = 1:5,
y = 6:10,
row.names = LETTERS[1:5]
)
Y <- c(D = 44, B = 55, Z = 22)
append_column(X, Y, after = 3)
Convert Row Names to an Explicit Column
Description
Convert Row Names to an Explicit Column
Usage
append_rownames(x, ...)
## S4 method for signature 'data.frame'
append_rownames(x, after = 0, remove = TRUE, var = "rownames")
Arguments
x |
A |
... |
Currently not used. |
after |
A length-one |
remove |
A |
var |
A |
Value
A data.frame
.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
assign()
,
compact()
,
count()
,
detect()
,
discard()
,
get()
,
keep()
,
seek()
Examples
X <- data.frame(
x = 1:5,
y = 6:10,
z = LETTERS[1:5]
)
## Assign column to row names
(Y <- assign_rownames(X, 3))
## Append row names to data.frame
(Z <- append_rownames(Y))
Deprecated Functions in arkhe
Description
These functions still work but will be removed (defunct) in the next version.
Usage
needs(...)
assert_dimensions(...)
compact_cols(...)
discard_cols(...)
keep_cols(...)
Check Numeric Trend
Description
Check Numeric Trend
Usage
assert_constant(x, ...)
assert_decreasing(x, ...)
assert_increasing(x, ...)
Arguments
x |
A |
... |
Extra parameters to be passed to internal methods. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Object Dimensions
Description
Check Object Dimensions
Usage
assert_dim(x, expected)
assert_nrow(x, expected)
assert_ncol(x, expected)
Arguments
x |
An object to be checked. |
expected |
An appropriate expected value. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Object Filling
Description
Checks if an object is (not) empty.
Usage
assert_empty(x)
assert_filled(x)
Arguments
x |
An object to be checked. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Infinite Values
Description
Checks if an object contains any infinite (Inf
) values.
Usage
assert_infinite(x)
Arguments
x |
An object to be checked. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Object Length(s)
Description
Check Object Length(s)
Usage
assert_length(
x,
expected,
allow_empty = empty,
allow_null = FALSE,
empty = FALSE
)
assert_lengths(x, expected)
Arguments
x |
An object to be checked. |
expected |
An appropriate expected value. |
allow_empty |
|
allow_null |
A |
empty |
Deprecated. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Numeric Relations
Description
Check Numeric Relations
Usage
assert_lower(x, y, ...)
assert_greater(x, y, ...)
Arguments
x , y |
A |
... |
Extra parameters to be passed to internal methods. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Missing Values
Description
Checks if an object contains any missing (NA
, NaN
) values.
Usage
assert_missing(x)
Arguments
x |
An object to be checked. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Object Names
Description
Check Object Names
Usage
assert_names(x, expected = NULL)
assert_rownames(x, expected = NULL)
assert_colnames(x, expected = NULL)
Arguments
x |
An object to be checked. |
expected |
An appropriate expected value. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check Numeric Values
Description
Check Numeric Values
Usage
assert_count(x, na.rm = FALSE, ...)
assert_whole(x, na.rm = FALSE, ...)
assert_positive(x, na.rm = FALSE, ...)
assert_negative(x, na.rm = FALSE, ...)
assert_odd(x, na.rm = FALSE, ...)
assert_even(x, na.rm = FALSE, ...)
Arguments
x |
A |
na.rm |
A |
... |
Extra parameters to be passed to internal methods. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_package()
,
assert_square()
,
assert_type()
,
assert_unique()
Check the Availability of a Package
Description
Check the Availability of a Package
Usage
assert_package(x, ask = interactive())
Arguments
x |
A |
ask |
A |
Details
assert_package()
is designed for use inside other functions in your own
package to check for the availability of a suggested package.
If the required packages are not available and R is running interactively, the user will be asked to install the packages.
Value
Invisibly returns NULL
.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_square()
,
assert_type()
,
assert_unique()
Check Matrix
Description
Check Matrix
Usage
assert_square(x)
assert_symmetric(x)
Arguments
x |
A |
Value
Throw an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_type()
,
assert_unique()
Check Data Types
Description
Check Data Types
Usage
assert_type(x, expected, allow_empty = TRUE, allow_null = FALSE)
assert_scalar(x, expected)
assert_function(x)
Arguments
x |
An object to be checked. |
expected |
A |
allow_empty |
|
allow_null |
A |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_unique()
Check Duplicates
Description
Checks if an object contains duplicated elements.
Usage
assert_unique(x)
Arguments
x |
An object to be checked. |
Value
Throws an error, if any, and returns x
invisibly otherwise.
Author(s)
N. Frerebeau
See Also
Other checking methods:
assert_constant()
,
assert_dim()
,
assert_empty()
,
assert_infinite()
,
assert_length()
,
assert_lower()
,
assert_missing()
,
assert_names()
,
assert_numeric
,
assert_package()
,
assert_square()
,
assert_type()
Assign a Specific Row/Column to the Column/Row Names
Description
Assign a Specific Row/Column to the Column/Row Names
Usage
assign_colnames(x, ...)
assign_rownames(x, ...)
## S4 method for signature 'data.frame'
assign_rownames(x, column, remove = TRUE)
## S4 method for signature 'data.frame'
assign_colnames(x, row, remove = TRUE)
Arguments
x |
A |
... |
Currently not used. |
column |
A length-one |
remove |
A |
row |
A length-one |
Value
A data.frame
.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
compact()
,
count()
,
detect()
,
discard()
,
get()
,
keep()
,
seek()
Examples
X <- data.frame(
x = 1:5,
y = 6:10,
z = LETTERS[1:5]
)
## Assign column to row names
(Y <- assign_rownames(X, 3))
## Append row names to data.frame
(Z <- append_rownames(Y))
Nonparametric Bootstrap Estimation
Description
Samples randomly from the elements of object
with replacement.
Usage
bootstrap(object, ...)
## S4 method for signature 'numeric'
bootstrap(
object,
do,
n,
...,
f = NULL,
level = 0.95,
interval = c("basic", "normal", "percentiles")
)
Arguments
object |
A |
... |
Extra arguments to be passed to |
do |
A |
n |
A non-negative |
f |
A |
level |
A length-one |
interval |
A |
Value
If f
is NULL
(the default), bootstrap()
returns a named numeric
vector with the following elements:
original
The observed value of
do
applied toobject
.mean
The bootstrap estimate of mean of
do
.bias
The bootstrap estimate of bias of
do
.error
The bootstrap estimate of standard error of
do
.lower
The lower limit of the bootstrap confidence interval at
level
.upper
The upper limit of the bootstrap confidence interval at
level
If f
is a function
, bootstrap()
returns the result of f
applied to
the n
values of do
.
Author(s)
N. Frerebeau
References
Davison, A. C. & Hinkley, D. V. (1997). Bootstrap Methods and Their Application. Cambridge Series on Statistical and Probabilistic Mathematics. Cambridge: Cambridge University Press.
See Also
Other resampling methods:
jackknife()
,
resample_multinomial()
,
resample_uniform()
Examples
x <- rnorm(20)
## Bootstrap
bootstrap(x, do = mean, n = 100)
## Estimate the 25th and 95th percentiles
quant <- function(x) { quantile(x, probs = c(0.25, 0.75)) }
bootstrap(x, n = 100, do = mean, f = quant)
## Get the n bootstrap estimates
(z <- bootstrap(x, n = 100, do = mean, f = function(x) { x }))
## Basic bootstrap confidence interval
confidence_bootstrap(z, level = 0.95, type = "basic", t0 = mean(x))
Class Diagnostic
Description
Class Diagnostic
Usage
check_class(object, conditions)
Arguments
object |
An object to which error messages are related. |
conditions |
A |
Value
Throw an error if conditions
is of non-zero length, invisibly returns
TRUE
if not.
Author(s)
N. Frerebeau
Remove Leading/Trailing Whitespace
Description
Remove Leading/Trailing Whitespace
Usage
clean_whitespace(x, ...)
## S4 method for signature 'data.frame'
clean_whitespace(x, which = c("both", "left", "right"), squish = TRUE)
## S4 method for signature 'matrix'
clean_whitespace(x, which = c("both", "left", "right"), squish = TRUE)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
which |
A |
squish |
A |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
x <- data.frame(
A = c(" Both ", " Left", "Right "),
B = 1:3
)
clean_whitespace(x, which = "both")
clean_whitespace(x, which = "left")
clean_whitespace(x, which = "right")
Remove Empty Rows/Columns
Description
Removes empty rows/columns in an array-like object.
Usage
compact(x, ...)
compact_columns(x, ...)
compact_rows(x, ...)
## S4 method for signature 'ANY'
compact(x, margin = 1, na.rm = FALSE, verbose = getOption("arkhe.verbose"))
## S4 method for signature 'ANY'
compact_columns(x, na.rm = FALSE, verbose = getOption("arkhe.verbose"))
## S4 method for signature 'ANY'
compact_rows(x, na.rm = FALSE, verbose = getOption("arkhe.verbose"))
Arguments
x |
An R object (should be a |
... |
Currently not used. |
margin |
A length-one |
na.rm |
A |
verbose |
A |
Details
A row/column is empty if it contains only zeros (if of type numeric
)
or zero length character strings (if of type character
).
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
count()
,
detect()
,
discard()
,
get()
,
keep()
,
seek()
Examples
## Create a data.frame
X <- data.frame(A = 0, B = 1:5, C = 6, D = "", F = letters[1:5])
X
## Remove empty columns
compact(X, margin = 2)
Concatenate
Description
Concatenates character vectors.
Usage
x %+% y
Arguments
x , y |
A |
Value
A character
vector.
See Also
Other utilities:
null
Conditions
Description
-
throw_error()
stops execution of the current expression and executes an error action. -
throw_warning()
generates a warning message. -
catch_conditions()
andcatch_message()
handles unusual conditions.
Usage
throw_error(.subclass, message, call = NULL, ...)
throw_warning(.subclass, message, call = NULL, ...)
catch_message(expr)
catch_conditions(expr)
Arguments
.subclass |
A |
message |
A |
call |
The call. |
... |
Extra arguments. |
expr |
An expression to be evaluated. |
Author(s)
N. Frerebeau
Confidence Interval for Binomial Proportions
Description
Computes Wald interval for a proportion at a desired level of significance.
Usage
confidence_binomial(object, ...)
## S4 method for signature 'numeric'
confidence_binomial(
object,
n,
level = 0.95,
method = "wald",
corrected = FALSE
)
Arguments
object |
A |
... |
Currently not used. |
n |
A length-one |
level |
A length-one |
method |
A |
corrected |
A |
Value
A length-two numeric
vector giving the lower and upper confidence
limits.
Author(s)
N. Frerebeau
See Also
Other summary statistics:
confidence_bootstrap()
,
confidence_mean()
,
confidence_multinomial()
,
interval_credible()
,
interval_hdr()
Examples
## Confidence interval for a mean
x <- seq(from = -4, to = 4, by = 0.01)
y <- dnorm(x)
mean(y)
confidence_mean(y, type = "student")
confidence_mean(y, type = "normal")
## Confidence interval for a propotion
confidence_binomial(118, n = 236)
x <- c(35, 74, 22, 69)
confidence_multinomial(x)
Nonparametric Bootstrap Confidence Interval
Description
Computes equi-tailed two-sided nonparametric confidence interval.
Usage
confidence_bootstrap(object, ...)
## S4 method for signature 'numeric'
confidence_bootstrap(
object,
level = 0.95,
type = c("basic", "normal", "student", "percentiles"),
t0 = NULL,
var_t0 = NULL,
var_t = NULL,
...
)
Arguments
object |
A |
... |
Currently not used. |
level |
A length-one |
type |
A |
t0 |
A length-one |
var_t0 |
A length-one |
var_t |
A |
Value
A length-two numeric
vector giving the lower and upper confidence
limits.
Author(s)
N. Frerebeau
References
Davison, A. C. & Hinkley, D. V. (1997). Bootstrap Methods and Their Application. Cambridge Series on Statistical and Probabilistic Mathematics. Cambridge: Cambridge University Press.
See Also
Other summary statistics:
confidence_binomial()
,
confidence_mean()
,
confidence_multinomial()
,
interval_credible()
,
interval_hdr()
Examples
x <- rnorm(20)
## Bootstrap
bootstrap(x, do = mean, n = 100)
## Estimate the 25th and 95th percentiles
quant <- function(x) { quantile(x, probs = c(0.25, 0.75)) }
bootstrap(x, n = 100, do = mean, f = quant)
## Get the n bootstrap estimates
(z <- bootstrap(x, n = 100, do = mean, f = function(x) { x }))
## Basic bootstrap confidence interval
confidence_bootstrap(z, level = 0.95, type = "basic", t0 = mean(x))
Confidence Interval for a Mean
Description
Computes a confidence interval for a mean at a desired level of significance.
Usage
confidence_mean(object, ...)
## S4 method for signature 'numeric'
confidence_mean(object, level = 0.95, type = c("student", "normal"))
Arguments
object |
A |
... |
Currently not used. |
level |
A length-one |
type |
A |
Value
A length-two numeric
vector giving the lower and upper confidence
limits.
Author(s)
N. Frerebeau
See Also
Other summary statistics:
confidence_binomial()
,
confidence_bootstrap()
,
confidence_multinomial()
,
interval_credible()
,
interval_hdr()
Examples
## Confidence interval for a mean
x <- seq(from = -4, to = 4, by = 0.01)
y <- dnorm(x)
mean(y)
confidence_mean(y, type = "student")
confidence_mean(y, type = "normal")
## Confidence interval for a propotion
confidence_binomial(118, n = 236)
x <- c(35, 74, 22, 69)
confidence_multinomial(x)
Confidence Interval for Multinomial Proportions
Description
Computes Wald interval for a proportion at a desired level of significance.
Usage
confidence_multinomial(object, ...)
## S4 method for signature 'numeric'
confidence_multinomial(
object,
level = 0.95,
method = "wald",
corrected = FALSE
)
Arguments
object |
A |
... |
Currently not used. |
level |
A length-one |
method |
A |
corrected |
A |
Value
A two column numeric
matrix
giving the lower and upper
confidence limits.
Author(s)
N. Frerebeau
See Also
Other summary statistics:
confidence_binomial()
,
confidence_bootstrap()
,
confidence_mean()
,
interval_credible()
,
interval_hdr()
Examples
## Confidence interval for a mean
x <- seq(from = -4, to = 4, by = 0.01)
y <- dnorm(x)
mean(y)
confidence_mean(y, type = "student")
confidence_mean(y, type = "normal")
## Confidence interval for a propotion
confidence_binomial(118, n = 236)
x <- c(35, 74, 22, 69)
confidence_multinomial(x)
Count Values Using a Predicate
Description
Counts values by rows/columns using a predicate function.
Usage
count(x, ...)
## S4 method for signature 'data.frame'
count(x, f, margin = 1, negate = FALSE, na.rm = FALSE, ...)
## S4 method for signature 'matrix'
count(x, f, margin = 1, negate = FALSE, na.rm = FALSE, ...)
Arguments
x |
An R object (should be a |
... |
Further arguments to be passed to |
f |
A predicate |
margin |
A length-one |
negate |
A |
na.rm |
A |
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
detect()
,
discard()
,
get()
,
keep()
,
seek()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X
## Count missing values in rows
count(X, f = is.na, margin = 1)
## Count non-missing values in columns
count(X, f = is.na, margin = 2, negate = TRUE)
Data Description
Description
Describes an object.
Usage
describe(x, ...)
## S4 method for signature 'ANY'
describe(x)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
Value
describe()
is called for its side-effects. Invisibly returns x
.
Author(s)
N. Frerebeau
See Also
Other data summaries:
sparsity()
Examples
## Create a data matrix
X <- matrix(sample(0:9, 15, TRUE), nrow = 3, ncol = 5)
## Add NA
k <- sample(1:15, 3, FALSE)
X[k] <- NA
## Sparsity
sparsity(X)
## Quick description
describe(X)
Find Rows/Columns Using a Predicate
Description
Finds rows/columns in an array-like object using a predicate function.
Usage
detect(x, ...)
## S4 method for signature 'ANY'
detect(x, f, margin = 1, negate = FALSE, all = FALSE, na.rm = FALSE, ...)
Arguments
x |
An R object (should be a |
... |
Further arguments to be passed to |
f |
A predicate |
margin |
A length-one |
negate |
A |
all |
A |
na.rm |
A |
Value
A logical
vector.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
count()
,
discard()
,
get()
,
keep()
,
seek()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X
## Find row with NA
detect(X, f = is.na, margin = 1)
## Find column without any NA
detect(X, f = is.na, margin = 2, negate = TRUE, all = TRUE)
Remove Rows/Columns Using a Predicate
Description
Removes rows/columns in an array-like object using a predicate function.
Usage
discard(x, ...)
discard_columns(x, ...)
discard_rows(x, ...)
## S4 method for signature 'ANY'
discard(
x,
f,
margin = 1,
negate = FALSE,
all = FALSE,
na.rm = FALSE,
verbose = getOption("arkhe.verbose"),
...
)
## S4 method for signature 'ANY'
discard_rows(
x,
f,
negate = FALSE,
all = FALSE,
na.rm = FALSE,
verbose = getOption("arkhe.verbose"),
...
)
## S4 method for signature 'ANY'
discard_columns(
x,
f,
negate = FALSE,
all = FALSE,
na.rm = FALSE,
verbose = getOption("arkhe.verbose"),
...
)
Arguments
x |
An R object (should be a |
... |
Further arguments to be passed to |
f |
A predicate |
margin |
A length-one |
negate |
A |
all |
A |
na.rm |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
count()
,
detect()
,
get()
,
keep()
,
seek()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X
## Remove row with any NA
discard(X, f = is.na, margin = 1, all = FALSE)
## Remove column with any NA
discard(X, f = is.na, margin = 2, all = FALSE)
Get Rows/Columns by Name
Description
Returns rows/columns selected by name in an array-like object.
Usage
get_columns(x, ...)
get_rows(x, ...)
## S4 method for signature 'ANY'
get_columns(x, select = NULL, names = NULL, ...)
## S4 method for signature 'ANY'
get_rows(x, select = NULL, names = NULL, ...)
Arguments
x |
An R object (should be a |
... |
Further arguments to be passed to |
select |
A |
names |
A |
Value
An object of the same sort as x
.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
count()
,
detect()
,
discard()
,
keep()
,
seek()
Examples
## Seek columns
seek_columns(iris, select = startsWith, prefix = "Petal")
seek_columns(iris, names = c("Petal.Length", "Petal.Width"))
## Get columns
x <- get_columns(iris, select = startsWith, prefix = "Petal")
head(x)
x <- get_columns(iris, names = c("Petal.Length", "Petal.Width"))
head(x)
Bayesian Credible Interval
Description
Computes the shortest credible interval within which an unobserved parameter value falls with a particular probability.
Usage
interval_credible(x, ...)
## S4 method for signature 'numeric'
interval_credible(x, level = 0.95)
Arguments
x |
A |
... |
Currently not used. |
level |
A length-one |
Value
A three-columns numeric
matrix
giving the lower and upper boundaries
of the credible interval and associated probability.
Author(s)
N. Frerebeau
See Also
Other summary statistics:
confidence_binomial()
,
confidence_bootstrap()
,
confidence_mean()
,
confidence_multinomial()
,
interval_hdr()
Examples
## HDR of the Old Faithful eruption times
interval_hdr(faithful$eruptions)
Highest Density Regions
Description
Highest Density Regions
Usage
interval_hdr(x, y, ...)
## S4 method for signature 'numeric,numeric'
interval_hdr(x, y, level = 0.954)
## S4 method for signature 'numeric,missing'
interval_hdr(x, level = 0.954, ...)
Arguments
x |
A |
y |
A |
... |
Further arguments to be passed to |
level |
A length-one |
Value
A three-columns numeric
matrix
giving the lower and upper boundaries
of the HPD interval and associated probabilities.
Author(s)
N. Frerebeau
References
Hyndman, R. J. (1996). Computing and graphing highest density regions. American Statistician, 50: 120-126. doi:10.2307/2684423.
See Also
Other summary statistics:
confidence_binomial()
,
confidence_bootstrap()
,
confidence_mean()
,
confidence_multinomial()
,
interval_credible()
Examples
## HDR of the Old Faithful eruption times
interval_hdr(faithful$eruptions)
Scalar Type Predicates
Description
Scalar Type Predicates
Usage
is_scalar_list(x)
is_scalar_atomic(x)
is_scalar_vector(x)
is_scalar_numeric(x)
is_scalar_integer(x)
is_scalar_double(x)
is_scalar_character(x)
is_scalar_logical(x)
Arguments
x |
An object to be tested. |
Value
A logical
scalar.
See Also
Other predicates:
predicate-attributes
,
predicate-data
,
predicate-matrix
,
predicate-names
,
predicate-numeric
,
predicate-trend
,
predicate-type
Jackknife Estimation
Description
Jackknife Estimation
Usage
jackknife(object, ...)
## S4 method for signature 'numeric'
jackknife(object, do, ..., f = NULL)
Arguments
object |
A |
... |
Extra arguments to be passed to |
do |
A |
f |
A |
Value
If f
is NULL
(the default), jackknife()
returns a named numeric
vector with the following elements:
original
The observed value of
do
applied toobject
.mean
The jackknife estimate of mean of
do
.bias
The jackknife estimate of bias of
do
.error
The jackknife estimate of standard error of
do
.
If f
is a function
, jackknife()
returns the result of f
applied to
the leave-one-out values of do
.
Author(s)
N. Frerebeau
See Also
Other resampling methods:
bootstrap()
,
resample_multinomial()
,
resample_uniform()
Examples
x <- rnorm(20)
## Jackknife
jackknife(x, do = mean) # Sample mean
## Get the leave-one-out values instead of summary
jackknife(x, do = mean, f = function(x) { x })
Keep Rows/Columns Using a Predicate
Description
Keeps rows/columns in an array-like object using a predicate function.
Usage
keep(x, ...)
keep_columns(x, ...)
keep_rows(x, ...)
## S4 method for signature 'ANY'
keep(
x,
f,
margin = 1,
negate = FALSE,
all = FALSE,
na.rm = FALSE,
verbose = getOption("arkhe.verbose"),
...
)
## S4 method for signature 'ANY'
keep_rows(
x,
f,
negate = FALSE,
all = FALSE,
na.rm = FALSE,
verbose = getOption("arkhe.verbose"),
...
)
## S4 method for signature 'ANY'
keep_columns(
x,
f,
negate = FALSE,
all = FALSE,
na.rm = FALSE,
verbose = getOption("arkhe.verbose"),
...
)
Arguments
x |
An R object (should be a |
... |
Further arguments to be passed to |
f |
A predicate |
margin |
A length-one |
negate |
A |
all |
A |
na.rm |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
count()
,
detect()
,
discard()
,
get()
,
seek()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X
## Keep row without any NA
keep(X, f = is.na, margin = 1, negate = TRUE, all = TRUE)
## Keep row without any NA
keep(X, f = is.na, margin = 2, negate = TRUE, all = TRUE)
Label Percentages
Description
Label Percentages
Usage
label_percent(x, digits = NULL, trim = FALSE)
Arguments
x |
A |
digits |
An |
trim |
A |
Value
A character
vector.
Greatest Common Divisor
Description
Computes the greatest common divisor (GCD) of two integer using the Euclidean algorithm.
Usage
math_gcd(x, y)
## S4 method for signature 'numeric,numeric'
math_gcd(x, y)
Arguments
x , y |
A |
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other mathematic functions:
math_lcm()
Least Common Multiple
Description
Computes the lowest common multiple of the denominators of a set of fractions.
Usage
math_lcm(x, y)
## S4 method for signature 'numeric,numeric'
math_lcm(x, y)
Arguments
x , y |
A |
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other mathematic functions:
math_gcd()
Default value for NULL
Description
Replaces NULL
with a default value.
Usage
x %||% y
Arguments
x , y |
An object. |
Value
If x
is NULL
, returns y
; otherwise returns x
.
See Also
Other utilities:
concat
Attributes Predicates
Description
-
has_length()
checks how long is an object. -
is_empty()
checks is an object is empty (any zero-length dimensions).
Usage
has_length(x, n = NULL)
is_empty(x)
Arguments
x |
A |
n |
A length-one |
Value
A logical
scalar.
See Also
Other predicates:
is_scalar
,
predicate-data
,
predicate-matrix
,
predicate-names
,
predicate-numeric
,
predicate-trend
,
predicate-type
Utility Predicates
Description
-
has_missing()
andhas_infinite()
check if an object contains missing or infinite values. -
has_duplicates()
checks if an object has duplicated elements.
Usage
has_missing(x)
has_infinite(x)
has_duplicates(x)
is_unique(x, tolerance = sqrt(.Machine$double.eps), na.rm = FALSE)
Arguments
x |
A |
tolerance |
A |
na.rm |
A |
Value
A logical
scalar.
See Also
Other predicates:
is_scalar
,
predicate-attributes
,
predicate-matrix
,
predicate-names
,
predicate-numeric
,
predicate-trend
,
predicate-type
Matrix Predicates
Description
-
is_square()
checks if a matrix is square. -
is_symmetric()
checks if a matrix is symmetric.
Usage
is_square(x)
is_symmetric(x)
Arguments
x |
A |
Value
A logical
scalar.
See Also
Other predicates:
is_scalar
,
predicate-attributes
,
predicate-data
,
predicate-names
,
predicate-numeric
,
predicate-trend
,
predicate-type
Names Predicates
Description
Checks if an object is named.
Usage
has_names(x, names = NULL)
has_rownames(x, names = NULL)
has_colnames(x, names = NULL)
Arguments
x |
A |
names |
A |
Value
A logical
scalar.
See Also
Other predicates:
is_scalar
,
predicate-attributes
,
predicate-data
,
predicate-matrix
,
predicate-numeric
,
predicate-trend
,
predicate-type
Numeric Predicates
Description
Check numeric objects:
-
is_zero()
checks if an object contains only zeros. -
is_odd()
andis_even()
check if a number is odd or even, respectively. -
is_positive()
andis_negative
check if an object contains only (strictly) positive or negative numbers. -
is_whole()
checks if an object only contains whole numbers.
Usage
is_zero(x, tolerance = sqrt(.Machine$double.eps), ...)
is_odd(x, ...)
is_even(x, ...)
is_positive(x, strict = FALSE, ...)
is_negative(x, strict = FALSE, ...)
is_whole(x, tolerance = sqrt(.Machine$double.eps), ...)
Arguments
x |
A |
tolerance |
A |
... |
Currently not used. |
strict |
A |
Value
A logical
vector.
See Also
Other predicates:
is_scalar
,
predicate-attributes
,
predicate-data
,
predicate-matrix
,
predicate-names
,
predicate-trend
,
predicate-type
Numeric Trend Predicates
Description
Check numeric objects:
-
is_constant()
checks for equality among all elements of a vector. -
is_increasing()
andis_decreasing()
check if a sequence of numbers is monotonically increasing or decreasing, respectively.
Usage
is_constant(x, tolerance = sqrt(.Machine$double.eps), na.rm = FALSE)
is_increasing(x, na.rm = FALSE)
is_decreasing(x, na.rm = FALSE)
is_greater(x, y, strict = FALSE, na.rm = FALSE)
is_lower(x, y, strict = FALSE, na.rm = FALSE)
Arguments
x , y |
A |
tolerance |
A |
na.rm |
A |
strict |
A |
Value
A logical
scalar.
See Also
Other predicates:
is_scalar
,
predicate-attributes
,
predicate-data
,
predicate-matrix
,
predicate-names
,
predicate-numeric
,
predicate-type
Type Predicates
Description
Type Predicates
Usage
is_list(x)
is_atomic(x)
is_vector(x)
is_numeric(x)
is_integer(x)
is_double(x)
is_character(x)
is_logical(x)
is_error(x)
is_warning(x)
is_message(x)
Arguments
x |
An object to be tested. |
Value
A logical
scalar.
See Also
Other predicates:
is_scalar
,
predicate-attributes
,
predicate-data
,
predicate-matrix
,
predicate-names
,
predicate-numeric
,
predicate-trend
Remove Rows/Columns with Infinite Values
Description
Removes rows/columns that contain infinite values.
Usage
remove_Inf(x, ...)
## S4 method for signature 'ANY'
remove_Inf(x, margin = 1, all = FALSE, verbose = getOption("arkhe.verbose"))
Arguments
x |
An R object (should be a |
... |
Currently not used. |
margin |
A length-one |
all |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add Inf
k <- sample(1:25, 3, FALSE)
X[k] <- Inf
X
## Remove rows with Inf
remove_Inf(X, margin = 1)
## Replace Inf with zeros
replace_Inf(X, value = 0)
Remove Rows/Columns with Missing Values
Description
Removes rows/columns that contain missing values.
Usage
remove_NA(x, ...)
## S4 method for signature 'ANY'
remove_NA(x, margin = 1, all = FALSE, verbose = getOption("arkhe.verbose"))
Arguments
x |
An R object (should be a |
... |
Currently not used. |
margin |
A length-one |
all |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X
## Remove rows with NA
remove_NA(X, margin = 1)
## Replace NA with zeros
replace_NA(X, value = 0)
Remove Constant Columns
Description
Remove Constant Columns
Usage
remove_constant(x, ...)
## S4 method for signature 'ANY'
remove_constant(x, na.rm = FALSE, verbose = getOption("arkhe.verbose"))
Arguments
x |
An R object (should be a |
... |
Currently not used. |
na.rm |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
## Create a data.frame
X <- data.frame(A = 1, B = 1:3)
X
remove_constant(X)
## Add NA
X[1, 1] <- NA
remove_constant(X)
remove_constant(X, na.rm = TRUE)
Remove Rows/Columns with Empty String
Description
Removes rows/columns that contain empty strings.
Usage
remove_empty(x, ...)
## S4 method for signature 'ANY'
remove_empty(x, margin = 1, all = FALSE, verbose = getOption("arkhe.verbose"))
Arguments
x |
An R object (should be a |
... |
Currently not used. |
margin |
A length-one |
all |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(LETTERS, 25, TRUE), nrow = 5, ncol = 5)
## Add empty string
k <- sample(1:25, 3, FALSE)
X[k] <- ""
X
## Remove rows with empty strings
remove_empty(X, margin = 1)
## Replace empty strings
replace_empty(X, value = "XXX")
Remove Rows/Columns with Zeros
Description
Removes rows/columns that contain zeros.
Usage
remove_zero(x, ...)
## S4 method for signature 'ANY'
remove_zero(x, margin = 1, all = FALSE, verbose = getOption("arkhe.verbose"))
Arguments
x |
An R object (should be a |
... |
Currently not used. |
margin |
A length-one |
all |
A |
verbose |
A |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add zero
k <- sample(1:25, 3, FALSE)
X[k] <- 0
X
## Remove rows with zero
remove_zero(X, margin = 1)
## Replace zero
replace_zero(X, value = 1)
Replace Infinite Values
Description
Replaces infinite values values.
Usage
replace_Inf(x, ...)
## S4 method for signature 'matrix'
replace_Inf(x, value = 0)
## S4 method for signature 'data.frame'
replace_Inf(x, value = 0)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
value |
A possible replacement value. |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_NA()
,
replace_empty()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add Inf
k <- sample(1:25, 3, FALSE)
X[k] <- Inf
X
## Remove rows with Inf
remove_Inf(X, margin = 1)
## Replace Inf with zeros
replace_Inf(X, value = 0)
Replace Missing Values
Description
Replaces missing values values.
Usage
replace_NA(x, ...)
## S4 method for signature 'matrix'
replace_NA(x, value = 0)
## S4 method for signature 'data.frame'
replace_NA(x, value = 0)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
value |
A possible replacement value. |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_empty()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X
## Remove rows with NA
remove_NA(X, margin = 1)
## Replace NA with zeros
replace_NA(X, value = 0)
Replace Empty String
Description
Replaces empty strings.
Usage
replace_empty(x, ...)
## S4 method for signature 'matrix'
replace_empty(x, value)
## S4 method for signature 'data.frame'
replace_empty(x, value)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
value |
A possible replacement value. |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(LETTERS, 25, TRUE), nrow = 5, ncol = 5)
## Add empty string
k <- sample(1:25, 3, FALSE)
X[k] <- ""
X
## Remove rows with empty strings
remove_empty(X, margin = 1)
## Replace empty strings
replace_empty(X, value = "XXX")
Replace Zeros
Description
Replaces zeros.
Usage
replace_zero(x, ...)
## S4 method for signature 'matrix'
replace_zero(x, value)
## S4 method for signature 'data.frame'
replace_zero(x, value)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
value |
A possible replacement value. |
Author(s)
N. Frerebeau
See Also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_empty()
Examples
## Create a data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
## Add zero
k <- sample(1:25, 3, FALSE)
X[k] <- 0
X
## Remove rows with zero
remove_zero(X, margin = 1)
## Replace zero
replace_zero(X, value = 1)
Draw Multinomial Random Sample
Description
Draws a random (sub)sample from a multinomial distribution.
Usage
resample_multinomial(object, ...)
## S4 method for signature 'numeric'
resample_multinomial(object, n, size = sum(object), ...)
Arguments
object |
A length- |
... |
Currently not used. |
n |
A non-negative |
size |
A non-negative |
Value
A numeric
matrix
with n
rows and k
columns.
Author(s)
N. Frerebeau
See Also
Other resampling methods:
bootstrap()
,
jackknife()
,
resample_uniform()
Examples
## Uniform distribution
x <- rnorm(20)
resample_uniform(x, n = 10)
## Multinomial distribution
x <- sample(1:100, 20, TRUE)
resample_multinomial(x, n = 10)
Draw Uniform Random Sample
Description
Draws a random (sub)sample (with or without replacement).
Usage
resample_uniform(object, ...)
## S4 method for signature 'numeric'
resample_uniform(object, n, size = length(object), replace = FALSE, ...)
Arguments
object |
A |
... |
Currently not used. |
n |
A non-negative |
size |
A non-negative |
replace |
A |
Value
A numeric
matrix
with n
rows and size
columns.
Author(s)
N. Frerebeau
See Also
Other resampling methods:
bootstrap()
,
jackknife()
,
resample_multinomial()
Examples
## Uniform distribution
x <- rnorm(20)
resample_uniform(x, n = 10)
## Multinomial distribution
x <- sample(1:100, 20, TRUE)
resample_multinomial(x, n = 10)
Rescale Continuous Vector (minimum, midpoint, maximum)
Description
Rescales continuous vector to have specified minimum, midpoint and maximum.
Usage
scale_midpoint(x, to = c(0, 1), from = range(x, finite = TRUE), midpoint = 0)
Arguments
x |
A |
to |
A length-two |
from |
A length-two |
midpoint |
A length-one |
Value
A numeric
vector.
Note
For internal use only.
See Also
Other scales:
scale_range()
Rescale Continuous Vector (minimum, maximum)
Description
Rescales continuous vector to have specified minimum and maximum.
Usage
scale_range(x, to = c(0, 1), from = range(x, finite = TRUE))
Arguments
x |
A |
to |
A length-two |
from |
A length-two |
Value
A numeric
vector.
Note
For internal use only.
See Also
Other scales:
scale_midpoint()
Search Rows/Columns by Name
Description
Searches rows/columns by name in an array-like object.
Usage
seek_columns(x, ...)
seek_rows(x, ...)
## S4 method for signature 'data.frame'
seek_rows(x, select = NULL, names = NULL, ...)
## S4 method for signature 'matrix'
seek_rows(x, select = NULL, names = NULL, ...)
## S4 method for signature 'data.frame'
seek_columns(x, select = NULL, names = NULL, ...)
## S4 method for signature 'matrix'
seek_columns(x, select = NULL, names = NULL, ...)
Arguments
x |
An R object (should be a |
... |
Further arguments to be passed to |
select |
A |
names |
A |
Value
An integer
vector or NULL
.
Author(s)
N. Frerebeau
See Also
Other data preparation tools:
append_column()
,
append_rownames()
,
assign()
,
compact()
,
count()
,
detect()
,
discard()
,
get()
,
keep()
Examples
## Seek columns
seek_columns(iris, select = startsWith, prefix = "Petal")
seek_columns(iris, names = c("Petal.Length", "Petal.Width"))
## Get columns
x <- get_columns(iris, select = startsWith, prefix = "Petal")
head(x)
x <- get_columns(iris, names = c("Petal.Length", "Petal.Width"))
head(x)
Sparsity
Description
Computes data sparsity (proportion of zeros).
Usage
sparsity(x, ...)
## S4 method for signature 'matrix'
sparsity(x, count = FALSE)
## S4 method for signature 'data.frame'
sparsity(x, count = FALSE)
Arguments
x |
An R object (should be a |
... |
Currently not used. |
count |
A |
Details
If x
is a data.frame
, sparsity is computed on numeric
variables only.
Value
A length-one numeric
vector.
Author(s)
N. Frerebeau
See Also
Other data summaries:
describe()
Examples
## Create a data matrix
X <- matrix(sample(0:9, 15, TRUE), nrow = 3, ncol = 5)
## Add NA
k <- sample(1:15, 3, FALSE)
X[k] <- NA
## Sparsity
sparsity(X)
## Quick description
describe(X)
Validate a Condition
Description
Validate a Condition
Usage
validate(expr)
Arguments
expr |
An object to be evaluated. |
Value
Returns NULL
on success, otherwise returns the error as a string.
Author(s)
N. Frerebeau
Evaluate an Expression with a Temporarily Seed
Description
Evaluate an Expression with a Temporarily Seed
Usage
with_seed(expr, seed, ..., envir = parent.frame(), rounding = TRUE)
Arguments
expr |
An |
seed |
A single value to be passed to |
... |
Further arguments to be passed to |
envir |
The environment in which |
rounding |
A |
Value
The results of expr
evaluated.