I have the following table:
col1 | col2 | col3 | col4 |
---|---|---|---|
1 | 2 | 1 | 4 |
5 | 6 | 6 | 3 |
My goal is to find the max value per each row, and then find how many times it was repeated in the same row.
The resulting table should look like this:
col1 | col2 | col3 | col4 | max_val | repetition |
---|---|---|---|---|---|
1 | 2 | 1 | 4 | 4 | 1 |
5 | 6 | 6 | 3 | 6 | 2 |
Now to achieve this, I am doing the following for Max:
df%>% rowwise%>%
mutate(max=max(col1:col4))
However, I am struggling to find the repetition. My idea is to use this pseudo code in mutate: sum( "select current row entirely or only for some columns"==max). But I don't know how to select entire row or only some columns of it and use its content to do the check, i.e.: is it equal to the max. How can we do this in dplyr?