I am trying to look up the index or name of a data frame based on the maximum of the aggrate values of that data frame, for example:
df <- data.frame(
id = 1:6,
v1 = c(3, 20, 34, 23, 23, 56),
v2 = c(1, 3, 4, 10, 30, 40),
v3 = c(20, 35, 60, 60, 70, 80))
id v1 v2 v3
1 1 3 1 20
2 2 20 3 35
3 3 34 4 60
4 4 23 10 60
5 5 23 30 70
6 6 56 40 80
> colSums(as.data.frame(df[[1]]))
df[[1]]
21
> colSums(as.data.frame(df[[2]]))
df[[2]]
159
> colSums(as.data.frame(df[[3]]))
df[[3]]
88
So for example the maximum result using colSums
is 159, and I'm trying to figure out how to to return 'df[[2]]
'