the dataset like this:
a b c d
a1 b1 1 0
a1 b1 0 1
a1 b2 0 1
a1 b2 1 0
a2 b3 1 0
a2 b3 1 0
a2 b4 0 0
if a1&b1 as a pair, have the dummy of 1 and 0 for column c, and 0 and 1 for column d. I want to have the maximum dummy for each pair in each column.
output should be:
a b c d
a1 b1 1 1
a1 b2 1 1
a2 b3 1 0
a2 b4 0 0
I tried the function “slice_max(c, by (c(a,b))”, but it can only do one column each time, if I use it for column c first, for a1&b1 pair, column 2&3 will be deleted and d will be 0 only.
New contributor
Pang kalok is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.