name location total_cats total_cats_down total_cats_up total_cats_updown total_cats_downup total_cats_oe total_cats_ce ... total_cats_downup what_col
Annie NJ 44 23 33 33 39 99 33 88 total_cats_updown
Ryan BA 34 33 11 23 23 12 39 11 total_cats
above is my data frame. I have the columns total_cats, total_cats_down, total_cats_up, total_cats_updown, total_cats_downup...total_cats_oe, total_cats_ce... and for every other column from total_cats_down:total_cats_downup I have columns that end in _oe and _ce. I did not write them out so it is shorter to view. I want to make three new columns: total_cats_final, total_cats_oe_final, and total_cats_ce_final based on the value in the column that is listed in what_col.
for example, if what_col is total_cats_updown, then :
total_cats_final , total_cats_oe_final , total_cats_ce_final would have the values found in total_cats_updown, total_cats_updown_oe, total_cats_updown_ce
is there a shorter way to do this than just do a case_when + mutate for three new columns in the Tidyverse? this could be very lengthy and repetitive I feel. thank u<3