- #1
user366312
Gold Member
- 89
- 3
- TL;DR Summary
- What is the basic difference between `rep()` and `replicate()` in R?
R code:
random <- function()
{
sample(1:10, size=1)
}
> rep(random(), 4)
[1] 8 8 8 8
> rep(random(), 4)
[1] 2 2 2 2
> replicate(4, random())
[1] 3 6 10 3
Why is this difference?