You can use the ifelse
function to replace values in the second column based on pattern matching with the first column. Here is an example code snippet to achieve this:
304 chars10 lines
In this code, we first create a sample dataframe df
with two columns col1
and col2
. We then use ifelse
to check if the value in col1
matches the value in col2
, and if it does, we replace the value in col2
with the value in col1
.
gistlibby LogSnag