Kinda clumsy, but it seems like you need to go down the vector, no matter
f <- function(x, repl = c(1,0,0)) { sx <- seq(x) for (ii in seq_along(x)) if (x[ii] == repl[1L])
And your example
set.seed(1) head(n = 10, cbind(tag <- sample(c(0,1), 150, replace=TRUE, prob = c(0.7, 0.3)), tag2 = f(tag)))
And you can replace with whatever you want
(x <- c(0,0,1,1,1,1,1)); f(x, c(1,0,0,0)) # [1] 0 0 1 1 1 1 1 # [1] 0 0 1 0 0 0 1 (x <- c(0,0,1,1,1,1,1)); f(x, 1:3) # [1] 0 0 1 1 1 1 1 # [1] 0 0 1 2 3 1 2 ## courtesy of @Frank this would also work (x <- c(0,0,1,1,0,0,1)); f(x, 0:2) # [1] 0 0 1 1 0 0 1 # [1] 0 1 2 1 0 1 2