mardi 3 octobre 2017

Generating random numbers in two vectors in R given a specified condition

I am willing to create two vectors in R that contain values which a randomly drawn from a uniform distribution given a specified condition, that is for example if the number in vector A is < 50 then the number in vector B should be greater than 50.

I use this code but it is applied only on the first elements if the vectors

nrows = 20; A = NaNmatrix(1, nrows, 1); B = NaNmatrix(1, nrows, 1); repeat{A[] = round(runif(nrows, 10, 100), digits =2) B[] = round(runif(nrows,10, 100), digits =2) if(A>50 & B>50){break}}

Aucun commentaire:

Enregistrer un commentaire