I'm looking for an effective way to update data for multiple columns based on many different conditions.
When the condition is true I want to update multiple columns of a datframe. I'm prettty sure dplyr's case_when function can only return a single column.
See the code below, this is what I'm currently doing, is there a better alternative? .
To achieve the same with dplyr I would need 2x case_when statements, for the below example it doesn't seem like much but my real-world problem is ~20 conditions, and 4 columns. It's always the same columns that need to be updated but it can be different column or combinations of columns with logic in the triggering condition.
Thanks for your clean example of a method to achieve this!
I think for my example (in the real world) I need to keep the new values as close to each condition as possible so it's easy to tell for say it might be client X what we are adjusting certain values to be , rather than checking which object the condition is assigned to, it's position in the first list and then having to correctly read the same position in the second list for the values.
Yeah, I thought that might be a problem. My suggestion then would be to order the priority of conditions and test in a for() loop that breaks once the condition is met.