I have a dataset with 2 columns like in the screenshot below: Personal name, Company name
> dput(df)
structure(list(Name = c("ABC", "BCD", "CDE", "DEF", "EFG", "FGH",
"GHI", "HIJ", "IJK", "JKL"), Company = c("A", "A", "A", "A",
"B", "B", "C", "C", "C", "C")), class = "data.frame", row.names = c(NA,
-10L))
> df
Name Company
1 ABC A
2 BCD A
3 CDE A
4 DEF A
5 EFG B
6 FGH B
7 GHI C
8 HIJ C
9 IJK C
10 JKL C
How can I split the dataset into 2 subsets, each of the subsets has the same amount of people from the same company?
For example, in total, there are 4 people in Company A. Within Company A group, there are two subsets, i.e.,2 people in subset1, the other 2 in subset 2. similarly for companies B, C.
For an odd number of people in the same Campany, the tie can be break by randomly selecting a subset.
Thanks!