r - Data.frame copy and paste values based on a condition -
i have data frame following structure/values , go through data frame (by row) , paste values first column ("one") cells of other columns if not na:
my data:
1 2 3 4 1 bar_2_foo na na 1 2 mur_4_doo 1 na 2 3 bur_3_hoo na 1 na
what achieve:
1 2 3 4 1 bar_2_foo na na bar_2_foo_1 2 mur_4_doo mur_4_doo_1 na mur_4_doo_2 3 bur_3_hoo na bur_3_hoo_1 na
any ideas how achieve great. thanks.
is you're looking for?
mutate_at(data, two:four, function(i){ ifelse(!is.na(i), paste0(one, "_", i), i) } )
Comments
Post a Comment