Scale: Scale a vector

View source: R/Scale.R

ScaleR Documentation

Scale a vector

Description

Scale a vector

Usage

Scale(x, m = NULL, sd = NULL, oadvances = NULL)

Arguments

x

The original vector.

m

The expected Mean of the scaled vector.

sd

The expected Standard Deviation (unit) of the scaled vector.

oadvances

The distance the Origin of x advances by.

Details

To scale x, its origin, or unit (sd), or both, could be changed.

If m = 0 or NULL, and sd = NULL, x would be mean-centered.

If m is a non-zero number, and sd = NULL, the mean of x would be transformed to m.

If m = 0 or NULL, and sd = 1, x would be standardized to be its z-score with m = 0 and m = 1.

The standardized score is not necessarily the z-score. If neither m nor sd is NULL, x would be standardized to be a vector whose mean and standard deviation would be m and sd, respectively. To standardize x, the mean and standard deviation of x are needed and computed, for which the missing values of x are removed if any.

If oadvances is not NULL, the origin of x will advance with the standard deviation being unchanged. In this case, Scale() could be used to pick points in simple slope analysis for moderation models. Note that when oadvances is not NULL, m and sd must be NULL.

Value

The scaled vector.

Examples

(x <- rnorm(10, 5, 2))
# Mean-center x.
Scale(x)
# Transform the mean of x to 3.
Scale(x, m = 3)
# Transform x to its z-score.
Scale(x, sd = 1)
# Standardize x with m = 100 and sd = 15.
Scale(x, m = 100, sd = 15)
# The origin of x advances by 3.
Scale(x, oadvances = 3)

Keng documentation built on April 4, 2025, 1:37 a.m.