If I have a dataframe with 100 subjects, and each subject falls within 20 different groups, and each group has between 3-6 subjects.
I have a list of 10 colors (red, green, blue, etc). I want to assign a color to each subject in a group, for example, the first subject in group A is red, second subject in group A is green, third subject in group A is blue, etc. Then first subject in group B is red, second subject in group B is green, third subject in group B is blue, etc.
Can you please help me write a code for this?
Code added:
D<-data.frame(ID = c("01", "03", "04", "07", "08", "05", "10", "09", "12", "11", "16", "17", "15", "19", "26", "25", "20", "32", "28", "29", "31", "34", "35", "36", "37"), Group = c(1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6))
Color<- c("#3366cc","#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395",'#994499','#22AA99','#AAAA11','#6633CC','#E67300','#8B0707','#651067','#329262','#5574A6','#3B3EAC')