| Title: | Kirill's Miscellaneous Functions |
|---|---|
| Description: | A collection of useful functions not found anywhere else, mainly for programming: Pretty intervals, generalized lagged differences, checking containment in an interval, and an alternative interface to assign(). |
| Authors: | Kirill Müller [aut, cre] |
| Maintainer: | Kirill Müller <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1.9009 |
| Built: | 2026-05-24 02:41:06 UTC |
| Source: | https://github.com/krlmlr/kimisc |
This is an enhanced version of base::cut() that allows a custom
formatting to be applied to the values.
cut_format( x, breaks, include.lowest = FALSE, right = TRUE, ordered_result = FALSE, ..., format_fun = format, sep = ", ", paren = c("(", "[", ")", "]") )cut_format( x, breaks, include.lowest = FALSE, right = TRUE, ordered_result = FALSE, ..., format_fun = format, sep = ", ", paren = c("(", "[", ")", "]") )
x |
a numeric vector which is to be converted to a factor by cutting. |
breaks |
|
include.lowest |
logical, indicating if an ‘x[i]’ equal to
the lowest (or highest, for |
right |
logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa. |
ordered_result |
logical: should the result be an ordered factor? |
... |
Passed to |
format_fun |
|
sep |
|
paren |
|
https://stackoverflow.com/q/14456371/946850
cut_format(runif(10), seq(0, 1, by = 0.25), format_fun = function(x) paste(x * 100, "%")) cut_format(runif(10), seq(0, 1, by = 0.25), paren = c("<", "{", ">", "}"))cut_format(runif(10), seq(0, 1, by = 0.25), format_fun = function(x) paste(x * 100, "%")) cut_format(runif(10), seq(0, 1, by = 0.25), paren = c("<", "{", ">", "}"))
This function is a wrapper around export.list() that
exports variables by their name to another environment.
export(..., target.env = .GlobalEnv)export(..., target.env = .GlobalEnv)
... |
variables to be exported. |
target.env |
The target environment. Use the global environment by default. |
Invisible NULL.
Roland
https://stackoverflow.com/a/17484932/946850
local({ newly.created.var <- 5 export(newly.created.var) }) newly.created.var rm(newly.created.var)local({ newly.created.var <- 5 export(newly.created.var) }) newly.created.var rm(newly.created.var)
This function is a wrapper around assign() that
exports the contents of a named list to an environment. The variable names
in the target environment are constructed from the names of the list items
or taken from a separate argument.
export.list(arg.list, arg.names = names(arg.list), target.env = .GlobalEnv)export.list(arg.list, arg.names = names(arg.list), target.env = .GlobalEnv)
arg.list |
list of objects, possibly named. |
arg.names |
names to use for the items in the target environment. Use
the names of |
target.env |
The target environment. Use the global environment by default. |
Invisible NULL.
Roland
https://stackoverflow.com/a/17484932/946850
export.list(list(newly.created.var = 5)) newly.created.var rm(newly.created.var)export.list(list(newly.created.var = 5)) newly.created.var rm(newly.created.var)
Returns suitably lagged and iterated differences using arbitrary difference functions.
gdiff(x, lag = 1L, differences = 1L, FUN = `-`, ...)gdiff(x, lag = 1L, differences = 1L, FUN = `-`, ...)
x |
a numeric vector or matrix containing the values to be differenced. |
lag |
an integer indicating which lag to use. |
differences |
an integer indicating the order of the difference. |
FUN |
A distance function that accepts two parameters |
... |
further arguments to be passed to or from methods. |
If x is a vector of length n and differences = 1, then
the computed result is equal to the successive differences
FUN(x[(1+lag):n], x[1:(n-lag)]).
If difference is larger than one this algorithm is applied
recursively to x. Note that the returned value is a vector which is
shorter than x.
If x is a matrix then the difference operations are carried out on each
column separately.
gdiff(1:4) gdiff(1:4, FUN = `/`)gdiff(1:4) gdiff(1:4, FUN = `/`)
This function checks if the values in the x
parameter are contained in the interval (lo, hi].
NA values are treated as "not in the interval".
in.interval.lo(x, lo, hi)in.interval.lo(x, lo, hi)
x |
A vector of values. (Lists will be coerced to a numeric vector.) |
lo |
Left end of the interval. |
hi |
Right end of the interval. |
A boolean vector of the same length as x.
in.interval.ro(), nin.interval.lo(),
nin.interval.ro()
in.interval.lo(c(-1, 0, 1, 2), 0, 1) in.interval.lo(NA, 1, 3)in.interval.lo(c(-1, 0, 1, 2), 0, 1) in.interval.lo(NA, 1, 3)
This function checks if the values in the x
parameter are contained in the interval [lo, hi).
NA values are treated as "not in the interval".
in.interval.ro(x, lo, hi)in.interval.ro(x, lo, hi)
x |
A vector of values. (Lists will be coerced to a numeric vector.) |
lo |
Left end of the interval. |
hi |
Right end of the interval. |
A boolean vector of the same length as x.
in.interval.lo(), nin.interval.lo(),
nin.interval.ro()
in.interval.ro(c(-1, 0, 1, 2), 0, 1) in.interval.ro(NA, 1, 3)in.interval.ro(c(-1, 0, 1, 2), 0, 1) in.interval.ro(NA, 1, 3)
The "See also" section contains the deprecated functions in this package.
Other deprecated functions:
coalesce.na-deprecated,
df_to_list-deprecated,
hms.to.seconds-deprecated,
list_to_df-deprecated,
nc-deprecated,
nlist-deprecated,
ofactor-deprecated,
sample.rows-deprecated,
seconds.to.hms-deprecated,
thisfile-deprecated,
tll-deprecated,
vswitch-deprecated
This function checks if the values in the x
parameter are contained in the interval (lo, hi].
NA values are treated as "not in the interval".
nin.interval.lo(x, lo, hi)nin.interval.lo(x, lo, hi)
x |
A vector of values. (Lists will be coerced to a numeric vector.) |
lo |
Left end of the interval. |
hi |
Right end of the interval. |
A boolean vector of the same length as x.
in.interval.lo(), in.interval.ro(),
nin.interval.ro()
nin.interval.lo(c(-1, 0, 1, 2), 0, 1) nin.interval.lo(NA, 1, 3)nin.interval.lo(c(-1, 0, 1, 2), 0, 1) nin.interval.lo(NA, 1, 3)
This function checks if the values in the x
parameter are contained in the interval [lo, hi).
NA values are treated as "not in the interval".
nin.interval.ro(x, lo, hi)nin.interval.ro(x, lo, hi)
x |
A vector of values. (Lists will be coerced to a numeric vector.) |
lo |
Left end of the interval. |
hi |
Right end of the interval. |
A boolean vector of the same length as x.
in.interval.lo(), in.interval.ro(),
nin.interval.lo()
nin.interval.ro(c(-1, 0, 1, 2), 0, 1) nin.interval.ro(NA, 1, 3)nin.interval.ro(c(-1, 0, 1, 2), 0, 1) nin.interval.ro(NA, 1, 3)