I have a data:
df_1 <- data.frame(
cpf = c('37576865879', '02177190948')
)
I try:
library(tidyverse)
str_sub(string = df_1$cpf, start = 4, end = 6) <- 'xxx'
# cpf
#1 375xxx65879
#2 021xxx90948
The result is ok. But:
df_1 <- data.frame(
cpf = c('37576865879', '02177190948')
)
df_1 %>%
mutate(.data = ., var = str_sub(string = cpf, start = 4, end = 6) <- "xxx")
# cpf var
#1 37576865879 xxx
#2 02177190948 xxx
Only x
s appears into var
. How adjust this last function to get the complete vector?
# cpf var
#1 37576865879 375xxx65879
#2 02177190948 021xxx90948