Learn R Programming

exams.forge (version 1.0.10)

scale_to: Rescaling

Description

Rescales x such that for the rescaled data it holds: mean(scale_to(x, mean=target))==target and sd(scale_to(x, sd=target)==abs(target). A negative value of sd will change the sign of the x values.

Usage

scale_to(x, mean = 0, sd = 1)

Value

Rescaled data.

Arguments

x

numeric: vector of values

mean

numeric: mean of the rescaled x (default: 0)

sd

numeric: standard deviation of the transformed x (default: 1)

Examples

Run this code
x <- runif(50)
y <- scale_to(x, mean=0.1, sd=0.2)
mean(y)
sd(y)
y <- scale_to(x, mean=0.1, sd=-0.2)
mean(y)
sd(y)

Run the code above in your browser using DataLab