Personal I have a table in the R where I wanted to look for the highest value in a set of columns and given this greater value, return in a new column the name of the column in which this greater value was.
For example, given the df below I wanted to look up the highest value of each row between the columns of A
to F
and create a new column named colunaOriginal
containing the name of the column in which the largest was.
For the first line the largest value would be 100 (from column A) and the colunaA
information would be in the colunaOriginal
column.
df_maior_valor <-
structure(list(A = c(100, 49, 30, 11, 7, 0, 1, 5, 7, 12), B = c(50,
51, 20, 10, 3, 10, 2, 6, 3, 3), C = c(0, 1, 5, 2, 5, 0, 0, 2,
1, 1), D = c(0, 0, 1, 0, 1, 0, 0, 0, 3, 2), E = c(0, 0, 0, 0,
1, 0, 0, 0, 1, 0), F = c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0)), .Names = c("A",
"B", "C", "D", "E", "F"), row.names = c(NA, 10L), class = "data.frame")