mercredi 9 octobre 2019

random number generation in r with different length and then combine

For the following numbers

n.i=rpois(10,15)
n.i
 [1] 12 19  9 17 20  9 11 18 15 13

I would like to generate random number from norml distribution of size 12, 19,..., and 13 and then combine in a single column. I can do it separately, for example,

x1=rnorm(n.i[1])
 x1
 [1] -1.4684359  0.3243679  1.1562347 -1.5978675 -1.3778871  0.6678866 -0.2940829 -1.3842074  0.7557435
[10] -1.5554419 -0.2866167  0.6250479
.
.
.
x10=rnorm(n.i[10])
x10
 [1] -0.69302945 -0.09568832 -1.88538457 -0.26877610 -0.66092837 -0.33671428 -1.28805672 -2.26124749  0.12168687
[10]  0.96683385  0.04307080  0.42701123 -0.92463081

To combine, x=c(x1,x2,...,x10)

Can I use any for loop or built-in function to solve this problem? Any help is appreciated.




Aucun commentaire:

Enregistrer un commentaire