I want to select 5 rows from each values in column1 of df such that the output has at least 1 value for each unique value in column2. Also there should not be any duplicates in the output
column1 = rep(c("a","b"), each = 12)
column2 = rep(c(1,2,3), each = 4)
column3 = c("x1","x2","x3","x4","x5","x3","x6","x7","x8","x1","x9","x5","x6","x2","x3","x4","x7","x5","x6","x1","x4","x1","x6","x9")
df = data.frame(column1, column2, column3)
Here is a valid solution
sample_output_1 = data.frame(column1 = rep(c("a","b"), each = 5),
column2 = c(1,1,2,2,3,1,1,2,2,3),
column3 = c("x1","x2","x5","x3","x8","x6","x2","x5","x1","x9"))
Aucun commentaire:
Enregistrer un commentaire