How to draw elements (select elements randomly) from an array?

Asked

Viewed 4,170 times

6

How can I draw elements (select elements randomly) from a vector in the R? For example, I want to draw elements from this vector:

numeros = c(1,2,45,63,29,100,999,23.45,76.1)

1 answer

5


To draw, for example, ten values of the vector in question in pseudo-random form, one can do the following:

numeros <- c(1,2,45,63,29,100,999,23.45,76.1)
sample(numeros,size=10, replace=TRUE)

Note: replace=TRUE to allow repetitions and replace=FALSE otherwise.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.