regex - your friend, here:
sub('nr$', 'nummer', 'artikelnr')
$indicates "end of line", therefore nris replaced only by nummerwhen it appears at the end of the line.
subcan work on the whole vector, for example. for a character vector x, do:
sub('nr$', 'nummer', x)
source
share