Performs a normalization of data, i.e., it scales variables in the range 0 -
This is a special case of data_rescale()
.
normalize(x, ...)# S3 method for numeric
normalize(x, include_bounds = TRUE, verbose = TRUE, ...)
# S3 method for data.frame
normalize(
x,
include_bounds = TRUE,
select = NULL,
exclude = NULL,
ignore_case = FALSE,
verbose = TRUE,
...
)
A numeric vector, (grouped) data frame, or matrix. See 'Details'.
Arguments passed to or from other methods.
Logical, if TRUE
, return value may include 0 and 1.
If FALSE
, the return value is compressed, using Smithson and Verkuilen's
(2006) formula (x * (n - 1) + 0.5) / n
, to avoid zeros and ones in the
normalized variables. This can be useful in case of beta-regression, where
the response variable is not allowed to include zeros and ones.
Toggle warnings and messages on or off.
Variables that will be included when performing the required tasks. Can be either
a variable specified as a literal variable name (e.g., column_name
),
a string with the variable name (e.g., "column_name"
), or a character
vector of variable names (e.g., c("col1", "col2", "col3")
),
a formula with variable names (e.g., ~column_1 + column_2
),
a vector of positive integers, giving the positions counting from the left
(e.g. 1
or c(1, 3, 5)
),
a vector of negative integers, giving the positions counting from the
right (e.g., -1
or -1:-3
),
or one of the following select-helpers: starts_with("")
, ends_with("")
,
contains("")
, a range using :
or regex("")
.
If NULL
, selects all columns.
See select
, however, column names matched by the pattern
from exclude
will be excluded instead of selected. If NULL
(the default),
excludes no columns.
Logical, if TRUE
and when one of the select-helpers or
a regular expression is used in select
, ignores lower/upper case in the
search pattern when matching against variable names.
A normalized object.
If x
is a matrix, normalization is performed across all values (not
column- or row-wise). For column-wise normalization, convert the matrix to a
data.frame.
If x
is a grouped data frame (grouped_df
), normalization is performed
separately for each group.
Smithson M, Verkuilen J (2006). A Better Lemon Squeezer? Maximum-Likelihood Regression with Beta-Distributed Dependent Variables. Psychological Methods, 11(1), 54<U+2013>71.
Other transform utilities:
data_rescale()
,
data_reverse()
,
ranktransform()
,
standardize()
# NOT RUN {
normalize(c(0, 1, 5, -5, -2))
normalize(c(0, 1, 5, -5, -2), include_bounds = FALSE)
head(normalize(trees))
# }
Run the code above in your browser using DataLab