Assume we have text file:
text <- "Quantum entanglement is a physical phenomenon that occurs when pairs or groups of particles are generated, interact, or share spatial proximity in ways such that the quantum state of each particle cannot be described independently of the state of the others, even when the particles are separated by a large distance."
I want to search "item" and replace with "code" in data frame
df <- tibble::tribble( ~item, ~code, "Quantum entanglement", "A01", "physical phenomenon", "A02", "quantum state", "A03", "quantum mechanics", "A04" )
in vim, i will do it one by one
%s/Quantum entanglement/A01/g %s/physical phenomenon/A02/g %s/quantum state/A03/g %s/quantum mechanics/A04/g
However, if there are many
item, it will be very laborious work. So I want to ask:
is there a R function which is equivalent to search & replace in vim?