lundi 24 février 2020

R - How to select a random vector

I have 4 vectors that contain integers.

I want to perform calculations based on 2 of the vectors, selected randomly.

I tried creating a new vector containing all the vectors, but sample() only gives me the first element of each vector.

My vectors if it helps:

A <- c(4, 4, 4, 4, 0, 0)
B <- c(3, 3, 3, 3, 3, 3)
C <- c(6, 6, 2, 2, 2, 2)
D <- c(5, 5, 5, 1, 1, 1)

The output I wanted is for example: A, B or B, D or D, A etc.

A thousand thanks in advance!




Aucun commentaire:

Enregistrer un commentaire