![]() |
VOOZH | about |
The scale() function in R is used to center and/or scale the columns of a numeric matrix. It helps standardize data by transforming it to have a mean of 0 and standard deviation of 1 .
scale(x, center = TRUE, scale = TRUE)
Parameters:
In this example, a 2x5 matrix is created and then standardized using the scale() function, which centers each column by subtracting its mean and scales it by dividing by its standard deviation.
Output:
In this example, a 5x4 matrix is created and then the scale() function is used in two ways: first to center the matrix by subtracting a specified vector of values from each column and second to scale the matrix by dividing each column by a specified vector of values.
Output: