Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Created March 21, 2018 16:33
Show Gist options
  • Save arcaravaggi/bafe1982851078f9bc5b9f64d4568585 to your computer and use it in GitHub Desktop.
Save arcaravaggi/bafe1982851078f9bc5b9f64d4568585 to your computer and use it in GitHub Desktop.
Function for the truncation of normal distribution
# Function for truncation of normal distribution
# n = number of iterations (default = 1000)
# m = mean
# s = SD/SE/CI
# l = lower bounds (default = -100)
# u = upper bounds (default = 100)
# r = round to x integers (default = 5)
tnorm <- function(n = 1000, m, s, l = -100, u = 100, r = 5) {
tdist <- round(rnorm(n, m, s), r)
tdist[tdist < l] <- l
tdist[tdist > u] <- u
tdist
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment