I want to do a random sampling of the dataframe df such that each "group" have equal number of samples.
set.seed(1)
df = data.frame(matrix(rnorm(30), nrow=15), group = sample(LETTERS[1:3], 15, replace =TRUE))
i used library(dplyr); sample_n(df, 4)
, but this will do a random sampling of df.
Aucun commentaire:
Enregistrer un commentaire