mercredi 21 avril 2021

How can I randomly change the sign of numbers in a vector?

I have a long vector of numbers that vary in the their sign (e.g.):

data -> c(1,-23,67,-21,10,32,64,-34,-6,10)

Working in R, how do I create a new vector that contains the same list of numbers, but give them a random sign (either positive or negative). For each number, the probability of it being negative should be 0.5.

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire