I have a data.frame looks like this, there is no pattern in the data.
df <- data.frame(type = c("A", "B", "B", "B", "A", "C", "C", "B", "A", "C"),
salary = c(1, 1, 3, 4, 8, 6, 12, 8, 9, 11),
v1 = c(5, 15, 23, 95, 2, 6, 2, 10, 51, 93),
v2 = c(7, 2, 5, 9, 4, 50, 8, 42, 63, 70))
There are three types as column 1 shows (A,B,C). I want to find which group has the highest salary(column 2) in aggregation.
For example,
salary_A<- sum(df$salary[which(df$type =="A")])
salary_B<- sum(df$salary[which(df$type =="B")])
salary_C<- sum(df$salary[which(df$type =="C")])
In this case, C has the largest aggregated salary, I want the program to tell me it is 'C'. In reality, i have many groups, so it is not feasible to do it one by one like above.
Thank you so much,