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
your example shows total_cats_downup twice, this would be extremely awkward.
is your data really like that , or have you made a mistake in creating your example ?
I dont know if its shorter than your case statements (though it has potnetial to be greatly reduced if certain variables were guaranteed to be in the frame i.e. total_cats_updown_oe
thank u this is so incredibly helpful. do u have a recommendation for running a loop on this if I have so many columns I am making "final" versions of? im just changing the suffix and what the new column name would be