rnorm_pre Produces a random normally distributed vector with the specified correlation to one or more existing vectors

rnorm_pre(x, mu = 0, sd = 1, r = 0, empirical = FALSE, threshold = 1e-12)

## Arguments

x the existing vector or data table of all vectors desired mean of returned vector desired SD of returned vector desired correlation(s) between existing and returned vectors logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance for checking correlation matrix

vector

## Examples

v1 <- rnorm(10)
v2 <- rnorm_pre(v1, 0, 1, 0.5)
cor(v1, v2)
#> [1] 0.7712965
x <- rnorm_multi(50, 2, .5)
x\$y <- rnorm_pre(x, r = c(0.5, 0.25))
cor(x)
#>            X1         X2         y
#> X1 1.00000000 0.01447404 0.5566679
#> X2 0.01447404 1.00000000 0.2687557
#> y  0.55666790 0.26875572 1.0000000