Here's a base R option :
splitting the string on |
, pasting each word with corresponding Var_b
value and collapsing the string back.
test$Var_c <- mapply(function(x, y) paste0(x, y, collapse = '|'),
strsplit(test$Var_a, '|', fixed = TRUE), test$Var_b)
test
# Var_a Var_b Var_c
#1 A|B X AX|BX
#2 C|D|E X CX|DX|EX
#3 F X FX
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…