For an example:
set.seed(123)
library(stringi)
df<-data.frame(p=sprintf("%s", stri_rand_strings(11, 11, '[A-Z]')),
n=sample(1:10, 11, 1),
s=sprintf("%s", stri_rand_strings(11, 1, '[A-Z]')))
df
p n s
1 GPCMCEHPTEW 3 X
2 STDJRNJGBGX 8 P
3 VTEDZLMEPHF 6 L
4 RHVCVLTRLQA 4 Y
5 FSFVIRYDDRL 7 S
6 VZBLSCZGBRU 10 K
7 JJHCJENNYIM 8 A
8 CWKTELUBVHJ 4 O
9 IANRXAZHYRL 10 M
10 VBTJVNHUCVH 9 W
11 TZCWUKIFOXN 6 V
What I wanted is to create a new column new_p
where the character in p
at position n
is replaced by s
. Thus the first df$new_p[1]
should be GPXMCEHPTEW
.