Are these two code snippets equivalent, i.e. are they doing the same thing?
For what I understand from the help of sample they should do the same thing, i.e. both s1 and s2 are a random subset of x.
First snippet:
sz <- 5
x <- 1:10
s1 <- sample(x,size=sz,replace=F)
Second snippet:
sz <- 5
x <- 1:10
s2 <- c()
idx <- sample(1:length(x),size=sz,replace=F)
for ( i in idx ) {
s2 <- c(s2,x[i])
}
Yes.