# NOT RUN {
d <- iris[1:4, ]
# vectors
standardise(d$Petal.Length)
# Data frames
# overwrite
standardise(d, select = c("Sepal.Length", "Sepal.Width"))
# append
standardise(d, select = c("Sepal.Length", "Sepal.Width"), append = TRUE)
# append, suffix
standardise(d, select = c("Sepal.Length", "Sepal.Width"), append = "_std")
# standardizing with reference center and scale
d <- data.frame(
a = c(-2, -1, 0, 1, 2),
b = c(3, 4, 5, 6, 7)
)
# default standardization, based on mean and sd of each variable
standardize(d) # means are 0 and 5, sd ~ 1.581139
# standardization, based on mean and sd set to the same values
standardize(d, center = c(0, 5), scale = c(1.581, 1.581))
# standardization, mean and sd for each variable newly defined
standardize(d, center = c(3, 4), scale = c(2, 4))
# standardization, taking same mean and sd for each variable
standardize(d, center = 1, scale = 3)
# }
Run the code above in your browser using DataLab