Home > Software engineering >  Automatic creation of several vectors in R
Automatic creation of several vectors in R

Time:10-06

I would like to create several vectors automatically in R. Each vector contains several variables (integers), which are selected randomly according to ranges for each vector.

For instance, the following shall create 20 vectors with 3 integer variables between the given ranges.

Number of vectors: V=20

Amount variables: Var=3

1<= Var1 <=10

1<= Var2 <=30

1<= Var3 <=20

CodePudding user response:

You can use sample in sapply and replicate.

replicate(20, sapply(list(1:10, 1:30, 1:20), sample, 1), FALSE)
  • Related