-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathnormal-histogram.R
More file actions
46 lines (34 loc) · 795 Bytes
/
normal-histogram.R
File metadata and controls
46 lines (34 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Histogram of Random Normal Numbers
#
# Generates a random vector following a normal distribution
# and produces a histogram in png format
#
# If no arguments are provided, then defaul values are:
# - mean = 0
# - sd = 1
# number of observations
num_obs <- 1000
# reading arguments ('mean' and 'sd')
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
x <- rnorm(num_obs)
} else {
if (is.missing(args[1])) {
mean <- 0
} else {
mean <- as.numeric(args[1])
}
if (is.na(args[2])) {
sd <- 1
} else {
sd <- as.numeric(args[2])
}
x <- rnorm(num_obs, mean = mean, sd = sd)
}
print('Plotting histogram')
png('normal-histogram.png', pointsize = 18)
hist(x, las = 1, col = '#437899')
dev.off()
print('done!')
# random data
#x <- rnorm(n, mean = mean, sd = sd)