extract values from different variables based on criteria using case_when

In general this sort of problem is easier in "tall" format. So you might consider using tidyr to gather the data, then use row operations to select what you want, and then spread the data back into the shape you are working with.

It might be getting off-topic, but there was a really neat thread on using columns to select other columns earlier here (and my notes on that are here).

5 Likes