R: Transform an input vector into one with defined mean and...

statVec {propagate} | R Documentation

## Transform an input vector into one with defined mean and standard deviation

### Description

Transforms an input vector into one with defined μ and σ by using a scaled-and-shifted Z-transformation.

### Usage

    statVec(x, mean, sd)

### Arguments

`x` | the input vector to be transformed.
`mean` | the desired mean of the created vector.
`sd` | the desired standard deviation of the created vector.

### Details

Calculates vector V using a Z-transformation of the input vector X and subsequent scaling by `sd` and shifting by `mean`:

V = \frac{X - μ_X}{σ_X} \cdot \rm{sd} + \rm{mean}

### Value

A vector with defined μ and σ.

### Author(s)

Andrej-Nikolai Spiess

### Examples

    ## Create a 10-sized vector with mean = 10 and s.d. = 1.
    x <- rnorm(10, 5, 2)
    mean(x) ## => mean is not 5!
    sd(x) ## => s.d. is not 2!

    z <- statVec(x, 5, 2)
    mean(z) ## => mean is 5!
    sd(z) ## => s.d. is 2!

[Package propagate version 1.0-6 Index]