Title: | Miscellaneous (Stats) Helper Functions with Sane Defaults for Reporting |
---|---|
Description: | Helper functions that act as wrappers to more advanced statistical methods with the advantage of having sane defaults for quick reporting. |
Authors: | Aleksandar Blagotić <[email protected]> and Gergely Daróczi <[email protected]> |
Maintainer: | Gergely Daróczi <[email protected]> |
License: | AGPL-3 |
Version: | 1.1 |
Built: | 2025-01-10 04:46:37 UTC |
Source: | https://github.com/rapporter/rapportools |
Similar to rle
function, this function detects "runs" of adjacent integers, and displays vector of run lengths and list of corresponding integer sequences.
adj.rle(x)
adj.rle(x)
x |
a numeric vector with |
a list with two elements: vector of run lengths, and another list of values corresponding to generated sequences' lengths.
Gabor Grothendieck <[email protected]>
See original thread for more details https://stackoverflow.com/a/8467446/564164. Special thanks to Gabor Grothendieck for this one!
This function tests if given variable "appears" to be an integer. To qualify as such, two conditions need to be satisfied: it should be stored as numeric
object, and it should pass regular expression test if it consists only of digits.
alike.integer(x)
alike.integer(x)
x |
a numeric variable that is to be tested |
a logical value that indicates that tested variable "looks like" integer
Capitalises strings in provided character vector
capitalise(x)
capitalise(x)
x |
a character vector to capitalise |
character vector with capitalised string elements
capitalise(c("foo", "bar")) # [1] "Foo" "Bar"
capitalise(c("foo", "bar")) # [1] "Foo" "Bar"
A simple wrapper for cat
function that appends newline to output.
catn(...)
catn(...)
... |
arguments to be passed to |
None (invisible NULL
).
Takes multiple character arguments as left and right-hand side arguments of a formula, and concatenates them in a single string.
fml(left, right, join.left = " + ", join.right = " + ")
fml(left, right, join.left = " + ", join.right = " + ")
left |
a string with left-hand side formula argument |
right |
a character vector with right-hand side formula arguments |
join.left |
concatenation string for elements of character vector specified in |
join.right |
concatenation string for elements of character vector specified in |
fml("hp", c("am", "cyl")) # "hp ~ am + cyl"
fml("hp", c("am", "cyl")) # "hp ~ am + cyl"
A fraction in ordinary English language
fraction.to.string(x)
fraction.to.string(x)
x |
numeric |
string
This function uses htest.short
, to extract statistic and p-value from htest
-classed object. Main advantage of using htest
is that it's vectorised, and can accept multiple methods.
htest( x, ..., use.labels = getOption("rapport.use.labels"), use.method.names = TRUE, colnames = c("Method", "Statistic", "p-value") )
htest( x, ..., use.labels = getOption("rapport.use.labels"), use.method.names = TRUE, colnames = c("Method", "Statistic", "p-value") )
x |
arguments to be passed to function specified in |
... |
additional arguments for function specified in |
use.labels |
a logical value indicating whether variable labels should be placed in row names. If set to |
use.method.names |
use the string provided in |
colnames |
a character string containing column names |
Default parameters are read from options
:
'rapport.use.labels'.
a data.frame
with applied tests in rows, and their results (statistic and p-value) in columns
## Not run: library(nortest) htest(rnorm(100), shapiro.test) htest(rnorm(100), lillie.test, ad.test, shapiro.test) htest(mtcars, lillie.test) htest(mtcars, lillie.test, ad.test, shapiro.test) ## End(Not run)
## Not run: library(nortest) htest(rnorm(100), shapiro.test) htest(rnorm(100), lillie.test, ad.test, shapiro.test) htest(mtcars, lillie.test) htest(mtcars, lillie.test, ad.test, shapiro.test) ## End(Not run)
htest
ObjectsExtract value of statistic and its p-value from htest
object.
htest.short(x)
htest.short(x)
x |
|
named numeric vector with the value of statistic and its p-value
## Not run: htest.short(shapiro.test(rnorm(100))) ## End(Not run)
## Not run: htest.short(shapiro.test(rnorm(100))) ## End(Not run)
Calculates interquartile range of given variable. See univar
for details.
iqr(...)
iqr(...)
... |
parameters to be passed to |
a numeric value with variable's interquartile range
Checks if provided object is a boolean i.e. a length-one logical vector.
is.boolean(x)
is.boolean(x)
x |
an object to check |
a logical value indicating whether provided object is a boolean
## Not run: is.boolean(TRUE) # [1] TRUE # the following will work on most systems, unless you have tweaked global Rprofile is.boolean(T) # [1] TRUE is.boolean(1) # [1] FALSE is.string(c("foo", "bar")) # [1] FALSE ## End(Not run)
## Not run: is.boolean(TRUE) # [1] TRUE # the following will work on most systems, unless you have tweaked global Rprofile is.boolean(T) # [1] TRUE is.boolean(1) # [1] FALSE is.string(c("foo", "bar")) # [1] FALSE ## End(Not run)
Rails-inspired helper that checks if vector values are "empty", i.e. if it's: NULL
, zero-length, NA
, NaN
, FALSE
, an empty string or 0
. Note that unlike its native R is.<something>
sibling functions, is.empty
is vectorised (hence the "values").
is.empty(x, trim = TRUE, ...)
is.empty(x, trim = TRUE, ...)
x |
an object to check its emptiness |
trim |
trim whitespace? ( |
... |
additional arguments for |
## Not run: is.empty(NULL) # [1] TRUE is.empty(c()) # [1] TRUE is.empty(NA) # [1] TRUE is.empty(NaN) # [1] TRUE is.empty("") # [1] TRUE is.empty(0) # [1] TRUE is.empty(0.00) # [1] TRUE is.empty(" ") # [1] TRUE is.empty("foobar") # [1] FALSE is.empty(" ", trim = FALSE) # [1] FALSE # is.empty is vectorised! all(is.empty(rep("", 10))) # [1] TRUE all(is.empty(matrix(NA, 10, 10))) # [1] TRUE ## End(Not run)
## Not run: is.empty(NULL) # [1] TRUE is.empty(c()) # [1] TRUE is.empty(NA) # [1] TRUE is.empty(NaN) # [1] TRUE is.empty("") # [1] TRUE is.empty(0) # [1] TRUE is.empty(0.00) # [1] TRUE is.empty(" ") # [1] TRUE is.empty("foobar") # [1] FALSE is.empty(" ", trim = FALSE) # [1] FALSE # is.empty is vectorised! all(is.empty(rep("", 10))) # [1] TRUE all(is.empty(matrix(NA, 10, 10))) # [1] TRUE ## End(Not run)
Checks if provided object is a number, i.e. a length-one numeric vector.
is.number(x, integer = FALSE)
is.number(x, integer = FALSE)
x |
an object to check |
integer |
logical: check if number is integer |
a logical value indicating whether provided object is a string
is.number(3) # [1] TRUE is.number(3:4) # [1] FALSE is.number("3") # [1] FALSE is.number(NaN) # [1] TRUE is.number(NA_integer_) # [1] TRUE
is.number(3) # [1] TRUE is.number(3:4) # [1] FALSE is.number("3") # [1] FALSE is.number(NaN) # [1] TRUE is.number(NA_integer_) # [1] TRUE
Checks if provided object is a string i.e. a length-one character vector.
is.string(x)
is.string(x)
x |
an object to check |
a logical value indicating whether provided object is a string
is.string("foobar") # [1] TRUE is.string(1) # [1] FALSE is.string(c("foo", "bar")) # [1] FALSE
is.string("foobar") # [1] TRUE is.string(1) # [1] FALSE is.string(c("foo", "bar")) # [1] FALSE
Checks if object has "tabular" structure (not to confuse with table
) - in this particular case, that means matrix
and data.frame
objects only.
is.tabular(x)
is.tabular(x)
x |
an object to be checked for "tabular" format |
a logical value indicating that provided object has tabular structure
is.tabular(HairEyeColor[, , 1]) # [1] TRUE is.tabular(mtcars) # [1] TRUE is.tabular(table(mtcars$cyl)) # [1] FALSE is.tabular(rnorm(100)) # [1] FALSE is.tabular(LETTERS) # [1] FALSE is.tabular(pi) # [1] FALSE
is.tabular(HairEyeColor[, , 1]) # [1] TRUE is.tabular(mtcars) # [1] TRUE is.tabular(table(mtcars$cyl)) # [1] FALSE is.tabular(rnorm(100)) # [1] FALSE is.tabular(LETTERS) # [1] FALSE is.tabular(pi) # [1] FALSE
From rapport's point of view, a variable
is a non-NULL
atomic vector that has no dimension attribute (see dim
for details). This approach bypasses factor
issues with is.vector
, and also eliminates multidimensional vectors, such as matrices and arrays.
is.variable(x)
is.variable(x)
x |
an object to be checked for "variable" format |
a logical value indicating that provided object is a "variable"
is.variable(rnorm(100)) # [1] TRUE is.variable(LETTERS) # [1] TRUE is.variable(NULL) # [1] FALSE is.variable(mtcars) # [1] FALSE is.variable(HairEyeColor[, , 1]) # [1] FALSE is.variable(list()) # [1] FALSE
is.variable(rnorm(100)) # [1] TRUE is.variable(LETTERS) # [1] TRUE is.variable(NULL) # [1] FALSE is.variable(mtcars) # [1] FALSE is.variable(HairEyeColor[, , 1]) # [1] FALSE is.variable(list()) # [1] FALSE
Calculates kurtosis coefficient for given variable (see is.variable
), matrix
or a data.frame
.
kurtosis(x, na.rm = TRUE)
kurtosis(x, na.rm = TRUE)
x |
a |
na.rm |
should |
Tenjovic, L. (2000). Statistika u psihologiji - prirucnik. Centar za primenjenu psihologiju.
set.seed(0) x <- rnorm(100) kurtosis(x) kurtosis(matrix(x, 10)) kurtosis(mtcars) rm(x)
set.seed(0) x <- rnorm(100) kurtosis(x) kurtosis(matrix(x, 10)) kurtosis(mtcars) rm(x)
This function returns character value previously stored in variable's label
attribute. If none found, and fallback
argument is set to TRUE
(default), the function returns object's name (retrieved by deparse(substitute(x))
), otherwise NA
is returned with a warning notice.
label(x, fallback = TRUE, simplify = TRUE)
label(x, fallback = TRUE, simplify = TRUE)
x |
an R object to extract labels from |
fallback |
a logical value indicating if labels should fallback to object name(s) |
simplify |
coerce results to a vector ( |
a character vector with variable's label(s)
## Not run: x <- rnorm(100) label(x) # returns "x" label(x, FALSE) # returns NA and issues a warning label(mtcars$hp) <- "Horsepower" label(mtcars) # returns "Horsepower" instead of "hp" label(mtcars, FALSE) # returns NA where no labels are found label(sleep, FALSE) # returns NA for each variable and issues a warning ## End(Not run)
## Not run: x <- rnorm(100) label(x) # returns "x" label(x, FALSE) # returns NA and issues a warning label(mtcars$hp) <- "Horsepower" label(mtcars) # returns "Horsepower" instead of "hp" label(mtcars, FALSE) # returns NA where no labels are found label(sleep, FALSE) # returns NA for each variable and issues a warning ## End(Not run)
This function sets a label to a variable, by storing a character string to its label
attribute.
label(var) <- value
label(var) <- value
var |
a variable (see |
value |
a character value that is to be set as variable label |
## Not run: label(mtcars$mpg) <- "fuel consumption" x <- rnorm(100) (label(x) <- "pseudo-random normal variable") ## End(Not run)
## Not run: label(mtcars$mpg) <- "fuel consumption" x <- rnorm(100) (label(x) <- "pseudo-random normal variable") ## End(Not run)
Computes Goodman and Kruskal's lambda for given table.
lambda.test(table, direction = 0)
lambda.test(table, direction = 0)
table |
a |
direction |
numeric value of |
computed lambda value(s) for row/col of given table
Goodman, L.A., Kruskal, W.H. (1954) Measures of association for cross classifications. Part I. Journal of the American Statistical Association 49, 732–764
## Not run: ## quick example x <- data.frame(x = c(5, 4, 3), y = c(9, 8, 7), z = c(7, 11, 22), zz = c(1, 15, 8)) lambda.test(x) # 0.1 and 0.18333 lambda.test(t(x)) # 0.18333 and 0.1 ## historical data (see the references above: p. 744) men.hair.color <- data.frame( b1 = c(1768, 946, 115), b2 = c(807, 1387, 438), b3 = c(189, 746, 288), b4 = c(47, 53, 16) ) row.names(men.hair.color) <- paste0('a', 1:3) lambda.test(men.hair.color) lambda.test(t(men.hair.color)) ## some examples on mtcars lambda.test(table(mtcars$am, mtcars$gear)) lambda.test(table(mtcars$gear, mtcars$am)) lambda.test(table(mtcars$am, mtcars$gear), 1) lambda.test(table(mtcars$am, mtcars$gear), 2) ## End(Not run)
## Not run: ## quick example x <- data.frame(x = c(5, 4, 3), y = c(9, 8, 7), z = c(7, 11, 22), zz = c(1, 15, 8)) lambda.test(x) # 0.1 and 0.18333 lambda.test(t(x)) # 0.18333 and 0.1 ## historical data (see the references above: p. 744) men.hair.color <- data.frame( b1 = c(1768, 946, 115), b2 = c(807, 1387, 438), b3 = c(189, 746, 288), b4 = c(47, 53, 16) ) row.names(men.hair.color) <- paste0('a', 1:3) lambda.test(men.hair.color) lambda.test(t(men.hair.color)) ## some examples on mtcars lambda.test(table(mtcars$am, mtcars$gear)) lambda.test(table(mtcars$gear, mtcars$am)) lambda.test(table(mtcars$am, mtcars$gear), 1) lambda.test(table(mtcars$am, mtcars$gear), 2) ## End(Not run)
Combines warning
with sprintf
thus allowing string interpolated diagnostic messages.
messagef(s, ...)
messagef(s, ...)
s |
a character vector of format strings |
... |
values to be interpolated |
## Not run: messagef("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40) ## End(Not run)
## Not run: messagef("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40) ## End(Not run)
Returns the number of valid (non-NA
) values in a variable. This is a wrapper around univar
function with length
function passed in fn
argument, but with missing values previously removed. However, it's not possible to cancel NA
omission with this function (doing so will yield error).
n(...)
n(...)
... |
parameters to be passed to |
a numeric value with number of valid (non-NA) vector elements
This function returns character value previously stored in variable's name
attribute. If none found, the function defaults to object's name.
name(x)
name(x)
x |
an R (atomic or data.frame/list) object to extract names from |
a character value with variable's label
## Not run: name(mtcars$am) x <- 1:10 name(x) ## End(Not run)
## Not run: name(mtcars$am) x <- 1:10 name(x) ## End(Not run)
Returns a number of missing (NA
) values in a variable. This is a wrapper around univar
function with anonymous function passed to count number of NA
elements in a variable.
nmissing(...)
nmissing(...)
... |
parameters to be passed to |
a numeric value with number of missing vector elements
Returns the number of valid (non-NA
) values in a variable. This is a wrapper around univar
function with length
function passed in fn
argument, but with missing values previously removed. However, it's not possible to cancel NA
omission with this function (doing so will yield error).
nvalid(...)
nvalid(...)
... |
parameters to be passed to |
a numeric value with number of valid (non-NA) vector elements
Appends a percent sign to provided numerical value. Rounding is carried out according to value passed in decimals
formal argument (defaults to value specified in panderOptions('digits')
).
pct( x, digits = panderOptions("digits"), type = c("percent", "%", "proportion"), check.value = TRUE )
pct( x, digits = panderOptions("digits"), type = c("percent", "%", "proportion"), check.value = TRUE )
x |
a numeric value that is to be rendered to percent |
digits |
an integer value indicating number of decimal places |
type |
a character value indicating whether percent or proportion value was provided (partial match is allowed) |
check.value |
perform a sanity check to see if provided numeric value is correct (defaults to |
a character value with formatted percent
Calculates percentage of cases for provided variable and criteria specified in subset
argument. Function accepts numeric, factor and logical variables for x
parameter. If numeric and/or factor is provided, subsetting can be achieved via subset
argument. Depending on value of na.rm
argument, either valid (na.rm = TRUE
) or all cases (na.rm = FALSE
) are taken into account. By passing logical variable to x
, a sum of (TRUE
) elements is calculated instead, and valid percents are used (NA
are excluded).
percent(x, subset = NULL, na.rm = TRUE, pct = FALSE, ...)
percent(x, subset = NULL, na.rm = TRUE, pct = FALSE, ...)
x |
a numeric variable to be summarised |
subset |
an expression that evaluates to logical vector (defaults to |
na.rm |
should missing values be |
pct |
print percent string too? |
... |
additional arguments for |
a numeric or string depending on the value of pct
## Not run: set.seed(0) x <- sample(5, 100, replace = TRUE) percent(x > 2) ## End(Not run)
## Not run: set.seed(0) x <- sample(5, 100, replace = TRUE) percent(x > 2) ## End(Not run)
Aggregate table of descriptives according to functions provided in fn
argument. This function follows melt/cast approach used in reshape
package. Variable names specified in measure.vars
argument are treated as measure.vars
, while the ones in id.vars
are treated as id.vars
(see melt.data.frame
for details). Other its formal arguments match with corresponding arguments for cast
function. Some post-processing is done after reshaping, in order to get pretty row and column labels.
rp.desc( measure.vars, id.vars = NULL, fn, data = NULL, na.rm = FALSE, margins = TRUE, total.name = "Total", use.labels = getOption("rapport.use.labels") )
rp.desc( measure.vars, id.vars = NULL, fn, data = NULL, na.rm = FALSE, margins = TRUE, total.name = "Total", use.labels = getOption("rapport.use.labels") )
measure.vars |
either a character vector with variable names from |
id.vars |
same rules apply as in |
fn |
a list with functions or a character vector with function names |
data |
a |
na.rm |
a logical value indicating whether |
margins |
should margins be included? |
total.name |
a character string with name for "grand" margin (defaults to "Total") |
use.labels |
use labels instead of variable names in table header (handle with care, especially if you have lengthy labels). Defaults to value specified in |
a data.frame
with aggregated data
rp.desc("cyl", NULL, c(mean, sd), mtcars) rp.desc("cyl", "am", c(mean, sd), mtcars, margins = TRUE) rp.desc("hp", c("am", "gear"), c("Average" = mean, "Deviation" = sd), mtcars)
rp.desc("cyl", NULL, c(mean, sd), mtcars) rp.desc("cyl", "am", c(mean, sd), mtcars, margins = TRUE) rp.desc("hp", c("am", "gear"), c("Average" = mean, "Deviation" = sd), mtcars)
Display frequency table with counts, percentage, and cumulatives.
rp.freq( f.vars, data, na.rm = TRUE, include.na = FALSE, drop.unused.levels = FALSE, count = TRUE, pct = TRUE, cumul.count = TRUE, cumul.pct = TRUE, total.name = "Total", reorder = FALSE )
rp.freq( f.vars, data, na.rm = TRUE, include.na = FALSE, drop.unused.levels = FALSE, count = TRUE, pct = TRUE, cumul.count = TRUE, cumul.pct = TRUE, total.name = "Total", reorder = FALSE )
f.vars |
a character vector with variable names |
data |
a |
na.rm |
should missing values be removed? |
include.na |
should missing values be included in frequency table? |
drop.unused.levels |
should empty level combinations be left out |
count |
show frequencies? |
pct |
show percentage? |
cumul.count |
show cumulative frequencies? |
cumul.pct |
show cumulative percentage? |
total.name |
a sting containing footer label (defaults to "Total") |
reorder |
reorder the table based on frequencies? |
a data.frame
with a frequency table
## Not run: rp.freq(c("am", "cyl", "vs"), mtcars) ## End(Not run)
## Not run: rp.freq(c("am", "cyl", "vs"), mtcars) ## End(Not run)
A simple test for outliers. This functions returns all extreme values (if any) found in the specified vector.
rp.outlier(x)
rp.outlier(x)
x |
a numeric vector of values |
vector of outlier values
Credit goes to PaulHurleyuk: https://stackoverflow.com/a/1444548/564164
Lund, R. E. 1975, "Tables for An Approximate Test for Outliers in Linear Models", Technometrics, vol. 17, no. 4, pp. 473-476.
Prescott, P. 1975, "An Approximate Test for Outliers in Linear Models", Technometrics, vol. 17, no. 1, pp. 129-132.
## Not run: rp.outlier(mtcars$hp) rp.outlier(c(rep(1,100), 200)) rp.outlier(c(rep(1,100), 200,201)) ## End(Not run)
## Not run: rp.outlier(mtcars$hp) rp.outlier(c(rep(1,100), 200)) rp.outlier(c(rep(1,100), 200,201)) ## End(Not run)
Calculates standard deviation of given variable. See univar
for details.
sd(...)
sd(...)
... |
parameters to be passed to |
a numeric value with variable's standard deviation
Calculates standard error of mean for given variable. See univar
for details.
se.mean(...)
se.mean(...)
... |
parameters to be passed to |
a numeric value with standard error of mean
Calculates skewness coefficient for given variable (see is.variable
), matrix
or a data.frame
.
skewness(x, na.rm = TRUE)
skewness(x, na.rm = TRUE)
x |
a |
na.rm |
should |
Tenjovic, L. (2000). Statistika u psihologiji - prirucnik. Centar za primenjenu psihologiju.
set.seed(0) x <- rnorm(100) skewness(x) skewness(matrix(x, 10)) skewness(mtcars) rm(x)
set.seed(0) x <- rnorm(100) skewness(x) skewness(matrix(x, 10)) skewness(mtcars) rm(x)
This helper combines stop
function with sprintf
thus allowing string interpolated messages when execution is halted.
stopf(s, ...)
stopf(s, ...)
s |
a character vector of format strings |
... |
values to be interpolated |
a string containing message that follows execution termination
## Not run: stopf("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40) ## End(Not run)
## Not run: stopf("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40) ## End(Not run)
Pre-computed width of strings without actually calling to graphics and new.plot
. The function can only handle base ASCII characters and default width of those is estimated by using standard 12 pt serif
on a standard plot
. Non-ASCII characters are replaced by an underscore.
strwidthest(s)
strwidthest(s)
s |
string |
numeric value representing the total width of the provided string in millimeters
## Not run: strwidthrel('R') # 71 strwidthrel('R is awesome!') # 635 ## End(Not run)
## Not run: strwidthrel('R') # 71 strwidthrel('R is awesome!') # 635 ## End(Not run)
Synonym
synonym(word)
synonym(word)
word |
a word to look-up in 'rapportools::synonyms' |
a synonym if found in 'rapportools::synonyms' words
synonym('package') synonym('bar')
synonym('package') synonym('bar')
Without the l
parameter, this function returns the saved list of synonym words. If l
is set, then this word list is saved for future use.
synonyms(l)
synonyms(l)
l |
a grouped list of words |
{ synonyms(list(c('package', 'library'), c('foo', 'bar', 'baz'))) synonyms() }
{ synonyms(list(c('package', 'library'), c('foo', 'bar', 'baz'))) synonyms() }
Convert character vector to camelcase - capitalise first letter of each word.
tocamel(x, delim = "[^[:alnum:]]", upper = FALSE, sep = "", ...)
tocamel(x, delim = "[^[:alnum:]]", upper = FALSE, sep = "", ...)
x |
a character vector to be converted to camelcase |
delim |
a string containing regular expression word delimiter |
upper |
a logical value indicating if the first letter of the first word should be capitalised (defaults to |
sep |
a string to separate words |
... |
additional arguments to be passed to |
a character vector with strings put in camelcase
tocamel("foo.bar") ## [1] "fooBar" tocamel("foo.bar", upper = TRUE) ## [1] "FooBar" tocamel(c("foobar", "foo.bar", "camel_case", "a.b.c.d")) ## [1] "foobar" "fooBar" "camelCase" "aBCD"
tocamel("foo.bar") ## [1] "fooBar" tocamel("foo.bar", upper = TRUE) ## [1] "FooBar" tocamel(c("foobar", "foo.bar", "camel_case", "a.b.c.d")) ## [1] "foobar" "fooBar" "camelCase" "aBCD"
Removes leading and/or trailing space(s) from a character vector. By default, it removes both leading and trailing spaces.
trim.space( x, what = c("both", "leading", "trailing", "none"), space.regex = "[:space:]", ... )
trim.space( x, what = c("both", "leading", "trailing", "none"), space.regex = "[:space:]", ... )
x |
a character vector which values need whitespace trimming |
what |
which part of the string should be trimmed. Defaults to |
space.regex |
a character value containing a regex that defines a space character |
... |
additional arguments for |
a character vector with (hopefully) trimmed spaces
This function operates only on vectors or their subsets, by calculating a descriptive statistic specified in fn
argument.
univar(x, subset = NULL, fn, na.rm = TRUE, ...)
univar(x, subset = NULL, fn, na.rm = TRUE, ...)
x |
a numeric variable to be summarised |
subset |
an expression that evaluates to logical vector (defaults to |
fn |
a function or a function name to be applied on a variable or it's subset |
na.rm |
a logical value indicating whether |
... |
additional arguments for function specified in |
a numeric
A simple wrapper for gsub
that replaces all patterns from pattern
argument with ones in replacement
over vector provided in argument x
.
vgsub(pattern, replacement, x, ...)
vgsub(pattern, replacement, x, ...)
pattern |
see eponymous argument for |
replacement |
see eponymous argument for |
x |
see eponymous argument for |
... |
additional arguments for |
a character vector with string replacements
See original thread for more details https://stackoverflow.com/a/6954308/564164. Special thanks to user Jean-Robert for this one!
Combines warning
with sprintf
thus allowing string interpolated warnings.
warningf(s, ...)
warningf(s, ...)
s |
a character vector of format strings |
... |
values to be interpolated |
## Not run: warningf("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40) ## End(Not run)
## Not run: warningf("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40) ## End(Not run)