'Dplyr mutate minimum column name
I have a df with many columns but for this issue am focusing on four date columns A, B, C, D. I am using the following to create a column for the minimum date for that row.
mutate(MIN_DATE = pmin(A,B,C,D))
To create a column for the minimum date for that row.
A B C D MIN_DATE
1-1-20 1-2-20 1-10-20 2-10-20 1-1-20
1-2-20 1-4-20 1-11-20 2-1-20 1-2-20
1-3-20 1-5-20 1-20-20 2-3-20 1-3-20
What I would like to do is add another column which is the column name of the minimum date which would look like :
A B C D MIN_DATE MIN_COL
1-1-20 1-2-20 1-10-20 2-10-20 1-1-20 A
1-2-20 1-4-20 1-11-20 2-1-20 1-2-20 A
1-3-20 1-5-20 1-2-20 2-3-20 1-3-20 C
What is the easiest way to accomplish this, some combination of names and which.min()?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
