tags:

views:

55

answers:

1

How can I reference a matched string (or captured group) in R so as to append in a sub(). For instance, I would do it like this in sed to append a 'd' to the match

echo "66xx" | sed 's/[0-9][0-9]/&d/g'
66dxx
+7  A: 
> sub("([0-9][0-9])(.*)","\\1d\\2", "66xx")
[1] "66dxx"
gd047
I see, it is the escaping of the backslash I was missing. Thanks
frankc