for each I need to For each data set, set σ 2 = 10 and µj = j, where j = 1, . . . , 5, 000 is the index of a data set.
Asked
Active
Viewed 224 times
0
-
4This seems like homework. What have you done so far to try solving this yourself? – camille Dec 04 '19 at 18:18
-
Just trying to learn R :) thanks for you kind feedback tho – Datagirl Dec 05 '19 at 19:17
-
That's fine, but revisit the guidance for posting a [mcve]. It's expected that your question has some level of an example, code, expected output, research, etc – camille Dec 05 '19 at 19:38
2 Answers
1
We can use lapply
to loop through 1 to 5000 and design a simple function to apply the data to the rnorm
function.
lapply(1:5000, function(x) rnorm(n = 1000, mean = x, sd = sqrt(10)))

www
- 38,575
- 12
- 48
- 84
0
You can use purrr::map()
.
map(1:5000, ~ rnorm(n = 10000, mean = .x, sd = 10))
If you want to iterate over two different arguments to rnorm
:
n_arg <- c(rep(10000, 2500), rep(20000, 2500))
map2(1:5000, n_arg, ~ rnorm(n = .y, mean = .x, sd = 10))

Giovanni Colitti
- 1,982
- 11
- 24