Primeiro divida a string aplicando gregexpr/regmatches
a uma regex. Depois junta.se tudo outra vez com paste
.
my_string <- c("ADGALPASHA65CS7GWJMWHMWKRC3UPQXANXB9XMF0MH865")
tmp <- regmatches(my_string, gregexpr(".{3}", my_string))[[1]]
paste(tmp, collapse = " ")
#> [1] "ADG ALP ASH A65 CS7 GWJ MWH MWK RC3 UPQ XAN XB9 XMF 0MH 865"
Created on 2022-05-04 by the reprex package (v2.0.1)
Edição
Para modificar todos os elementos da coluna, é só generalizar o código acima. Não se escolhe só o primeiro membro da lista de gregexpr
e aplica-se o paste
a todos os elementos da lista num ciclo sapply
.
URL <- "https://docs.google.com/spreadsheets/d/1BW6F0vLzw3r7YsQ8lfQ6COZztoAsGoODLVj5_IIkr74/export?format=csv"
df1 <- read.csv(URL)
tmp <- with(df1, regmatches(my_string, gregexpr(".{3}", my_string)))
df1$string_with_spaces <- sapply(tmp, paste, collapse = " ")
df1
#> my_string string_with_spaces
#> 1 ADGALPASHAZ5A65GWJMWHMWKUPQXANXB9XMF0MH865 ADG ALP ASH AZ5 A65 GWJ MWH MWK UPQ XAN XB9 XMF 0MH 865
#> 2 ALPASHA65GWJMWHRC3UPQXANXB9XMF0MH865 ALP ASH A65 GWJ MWH RC3 UPQ XAN XB9 XMF 0MH 865
#> 3 ADGALPASHAZ5A65CS7GWJMWHMWKUPQXANXB9XMF0MH865 ADG ALP ASH AZ5 A65 CS7 GWJ MWH MWK UPQ XAN XB9 XMF 0MH 865
#> 4 ALPASHA65CS7GWJMWHUPQXANXB9XMF0MH865 ALP ASH A65 CS7 GWJ MWH UPQ XAN XB9 XMF 0MH 865
#> 5 AFBALPASHAZ5AZ6A65CS7GWJMWHUJXXANXB9XMF0MG AFB ALP ASH AZ5 AZ6 A65 CS7 GWJ MWH UJX XAN XB9 XMF 0MG
#> 6 AAUADBAPDLNCMDNXHQ0MH AAU ADB APD LNC MDN XHQ 0MH
#> 7 AAUADBLNCMDNXHQ0MH AAU ADB LNC MDN XHQ 0MH
#> 8 AAVADBANTASHA77CLFLNCMY7UPQXAN0MH058 AAV ADB ANT ASH A77 CLF LNC MY7 UPQ XAN 0MH 058
#> 9 AAVADBANTASHA77CLFDSALNCMY7UPQXAN0MH058 AAV ADB ANT ASH A77 CLF DSA LNC MY7 UPQ XAN 0MH 058
#> 10 ADBANTCLFDSAUPQXAN0MH058 ADB ANT CLF DSA UPQ XAN 0MH 058
#> 11 AAUADBAHUAPDLNCMDNXHQ0MH AAU ADB AHU APD LNC MDN XHQ 0MH
#> 12 AAUADBAHULNCMDNXHQ0MH AAU ADB AHU LNC MDN XHQ 0MH
#> 13 ADBANTA76CLFMR5UPQXAN0MH058 ADB ANT A76 CLF MR5 UPQ XAN 0MH 058
#> 14 ADBANTA76CLFDSALNCMR5UPQXAN0MH058 ADB ANT A76 CLF DSA LNC MR5 UPQ XAN 0MH 058
#> 15 ADBANTCLFDSALNCMY7UPQXAN0MH058 ADB ANT CLF DSA LNC MY7 UPQ XAN 0MH 058
#> 16 ADGALPASHA65CS7GWJMWHMWKRC3UPQXANXB9XMF0MH865 ADG ALP ASH A65 CS7 GWJ MWH MWK RC3 UPQ XAN XB9 XMF 0MH 865
#> 17 AAVADBANTA77CLFDSALNCMY7UPQXAN0MH058 AAV ADB ANT A77 CLF DSA LNC MY7 UPQ XAN 0MH 058
#> 18 ADBANTCLFDSALNCUPQXAN0MH058 ADB ANT CLF DSA LNC UPQ XAN 0MH 058
#> 19 ALPASHA65CS7GWJMWHMWKUPQXANXB9XMF0MH865 ALP ASH A65 CS7 GWJ MWH MWK UPQ XAN XB9 XMF 0MH 865
#> 20 ADGALPASHAZ5A65CS7GWJMWHMWKUPQXANXB9XMF ADG ALP ASH AZ5 A65 CS7 GWJ MWH MWK UPQ XAN XB9 XMF
#> 21 ALPAZ6A65CS7GWJMWHXANXB9XMF0MG865 ALP AZ6 A65 CS7 GWJ MWH XAN XB9 XMF 0MG 865
#> 22 ADBANTA76CLFDSAMRSUPQXAN0MH058 ADB ANT A76 CLF DSA MRS UPQ XAN 0MH 058
Created on 2022-05-04 by the reprex package (v2.0.1)