mardi 7 février 2023

calculate new random number considering distribution of already existing numbers in r

I have a dataframe with participants and I want to randomly assign them to a group (0,1). Each group should have approximately the same amount of participants. My problem: I will keep adding participants. So, when I calculate a new random number for that participant, it should take into accound the distribution of the random numbers I already have.

This is my code:

groupData <- data.frame(participant = c(1), Group = floor(runif(1, min=0, max=2))) 
groupData[nrow(groupData) + 1,] = c(2,floor(runif(1, min=0, max=2))) # with this I will be adding participants



Aucun commentaire:

Enregistrer un commentaire