Conditionally replace values in one column with values from another column using dplyr [duplicate]
问题 This question already has an answer here : Change value of variable with dplyr [duplicate] (1 answer) Closed 2 years ago . I want to replace the values in one column that match a certain condition with values in that same row from a different column. Consider this example: library(tidyverse) data <- tribble( ~X25, ~Other, "a", NA, "b", NA, "Other", "c", "Other", "d" ) View(data) # Works to change values in X25 within(data, { X25 <- ifelse(X25 == "Other", Other, X25) }) # Changes values in X25