gistlib
You can achieve this by using the dplyr package in R. Here's the code to accomplish the task:
dplyr
library(dplyr) # Create a sample data frame df <- data.frame(col1 = c("A", "B", "C", "D"), col2 = c("E", "B", "F", "A")) # Update col2 where col1 and col2 match df <- df %>% mutate(col2 = ifelse(col1 == col2, col1, col2)) df 247 chars12 lines
library(dplyr) # Create a sample data frame df <- data.frame(col1 = c("A", "B", "C", "D"), col2 = c("E", "B", "F", "A")) # Update col2 where col1 and col2 match df <- df %>% mutate(col2 = ifelse(col1 == col2, col1, col2)) df
This code will replace the values in col2 with the corresponding values in col1 if they match.
col2
col1
gistlibby LogSnag