partition | R Documentation |
Convert the selected columns of the data frame into either dummy logical columns, or into membership degrees of fuzzy sets, while leaving the remaining columns untouched. Each column selected for transformation typically yields in multiple columns in the output.
partition(
.data,
.what = everything(),
...,
.breaks = NULL,
.labels = NULL,
.na = TRUE,
.keep = FALSE,
.method = "crisp",
.right = TRUE
)
.data |
the data frame to be processed |
.what |
a tidyselect expression (see tidyselect syntax) specifying the columns to be transformed |
... |
optional other tidyselect expressions selecting additional columns to be processed |
.breaks |
for numeric columns, this has to be either an integer scalar
or a numeric vector. If |
.labels |
character vector specifying the names used to construct
the newly created column names. If |
.na |
if |
.keep |
if |
.method |
The method of transformation for numeric columns. Either
|
.right |
If |
Transformations performed by this function are typically useful as a
preprocessing step before using the dig()
function or some of its
derivatives (dig_correlations()
, dig_paired_baseline_contrasts()
,
dig_associations()
).
The transformation of selected columns differ based on the type. Concretely:
logical column x
is transformed into pair of logical columns,
x=TRUE
andx=FALSE
;
factor column x
, which has levels l1
, l2
, and l3
, is transformed
into three logical columns named x=l1
, x=l2
, and x=l3
;
numeric columnx
is transformed accordingly to .method
argument:
if .method="crisp"
, the column is first transformed into a factor
with intervals as factor levels and then it is processed as a factor
(see above);
for other .method
(triangle
or raisedcos
), several new columns
are created, where each column has numeric values from the interval
[0,1]
and represents a certain fuzzy set (either triangular or
raised-cosinal).
Details of transformation of numeric columns can be specified with
additional arguments (.breaks
, .labels
, .right
).
A tibble created by transforming .data
.
Michal Burda
# transform logical columns and factors
d <- data.frame(a = c(TRUE, TRUE, FALSE),
b = factor(c("A", "B", "A")),
c = c(1, 2, 3))
partition(d, a, b)
# transform numeric columns to logical columns (crisp transformation)
partition(CO2, conc:uptake, .method = "crisp", .breaks = 3)
# transform numeric columns to fuzzy sets (triangle transformation)
partition(CO2, conc:uptake, .method = "triangle", .breaks = 3)
# complex transformation with different settings for each column
CO2 |>
partition(Plant:Treatment) |>
partition(conc,
.method = "raisedcos",
.breaks = c(-Inf, 95, 175, 350, 675, 1000, Inf)) |>
partition(uptake,
.method = "triangle",
.breaks = c(-Inf, 7.7, 28.3, 45.5, Inf),
.labels = c("low", "medium", "high"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.