I need to set a label for each id in column a, based on the existing values for this id. For example, if the id 1 only has "F" then the result will be "Female", if only "M" then "Male" and if mixed, then "Mixed".
This is the dataframe base:
df=data.frame(
a=c(1,1,1,2,2,3,3,3,3,3),
b=c("F","M","F","M","M","F","F","F","F","F"))
And this is the expected result:
df$Result=c("Mixed", "Mixed", "Mixed", "Male", "Male", "Female", "Female", "Female", "Female", "Female")
a b Result
1 1 F Mixed
2 1 M Mixed
3 1 F Mixed
4 2 M Male
5 2 M Male
6 3 F Female
7 3 F Female
8 3 F Female
9 3 F Female
10 3 F Female
Someone could please help me to calculate this df$Result
column? Thanks in advance!