I want to add a new column in R which summarizes my subgroups into groups.
Here my example:
id = c(1,2,2,3,4,4,4,5,5,5,6,6,6)
subgroup = c("lightred","marine","cyan","rose","bordeaux","darkred","sky","gras","bottle","lightgreen","darkred","marine","lightgreen")
data = data.frame(cbind(id,subgroup))
> data
id subgroup
1 1 lightred
2 2 marine
3 2 cyan
4 3 rose
5 4 bordeaux
6 4 darkred
7 4 sky
8 5 gras
9 5 bottle
10 5 lightgreen
11 6 darkred
12 6 marine
13 6 lightgreen
Now I want to add a new column "colour" which groups the attributes into 3 gropus "red", "green" and "blue". Can I assign the subgroups to a variable first and then assign them to a group?
red = "lightred", "darkred" , "rose" , "bordeaux"
blue = "marine", "cyan", "sky"
green = "gras", "bottle" , "lightgreen"
It should look like this at the end:
> data
id subgroup colour
1 1 lightred red
2 2 marine blue
3 2 cyan blue
4 3 rose red
5 4 bordeaux red
6 4 darkred red
7 4 sky blue
8 5 gras green
9 5 bottle green
10 5 lightgreen green
11 6 darkred red
12 6 marine blue
13 6 lightgreen green
Thanks!