I have a dataframe with multiple columns where its rowSums
is either 1
either 0.9
.
If one column is 0.5
, than another one has to be 0.5
. If a column is 0.3
, then other two have to have the same value.
df <- data.frame(A = c(0, 0, 0.3, 0.5, 0, 0.3, 0.5), B = c(0, 0, 0.3, 0.5, 0, 0.3, 0.5),
C = c(1, 1, 0.3, 0, 1, 0.3, 0))
What I need in the end is another column (result
) that has the column names where the values > 0.
> df
A B C result
1 0.0 0.0 1.0 C
2 0.0 0.0 1.0 C
3 0.3 0.3 0.3 A-B-C
4 0.5 0.5 0.0 A-B
5 0.0 0.0 1.0 C
6 0.3 0.3 0.3 A-B-C
7 0.5 0.5 0.0 A-B
Thanks!