# [R] How generate random numbers from given vector???

arun smartpink111 at yahoo.com
Thu Oct 25 23:57:01 CEST 2012

```Hi,
Try this:
number1<-c(0,1,3,4,5,6,8)
rsidp<-function(x){
y<-sample(x,5,replace=TRUE)
y
}
rsidp(number1)
#[1] 3 0 6 8 4
rsidp(number1)
#[1] 1 8 8 6 4
rsidp(number1)
#[1] 8 3 6 6 6
A.K.

----- Original Message -----
From: Rlotus <yerlan_ at hotmail.com>
To: r-help at r-project.org
Cc:
Sent: Thursday, October 25, 2012 3:24 PM
Subject: [R] How generate random numbers from given vector???

I wanna generate random numbers from a vector...

for example number<-c(0,1,3,4,5,6,8)
so

rsidp<-function(x){
i=0
for (i in seq(1:x))

{y<-sample(number,x, replace=T)}
return(y)
}
so all random numbers have to be from vector "number";
so if I type rsidp(5)..... it has to give me 5 random numbers except 2,7,9
(because they are not in the vector "numbers"). help me plz with it (((

--
View this message in context: http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help