I have a dataframe that looks like so:
ID | One | Two | Three
A 0.6 0.4 0.2
B 0.2 0.32 0.12
C 0.1 0.24 0.14
D 0.62 0.12 0.19
What I would like to do is create three new fields based on the avg value per ID, the min value per ID, and then a final column that calls the associated column header (name) associated to that min value.
Output will look something like this:
ID | One | Two | Three | Avg | Min | Min Header
A 0.6 0.4 0.2 0.4 0.2 Three
B 0.2 0.32 0.12 0.21 0.12 Three
C 0.1 0.24 0.14 0.16 0.1 One
D 0.62 0.12 0.19 0.31 0.12 Two
I am currently using a group_by(ID) %>% summarise(avg = col1+col2+col3/3, min = pmin(col1,col2,col3) to create new dataframe but idk how to pull the column header as a new col in my group_by '%>%' method.
Any help would be greatly apprecaited!