Boa tarde, pessoal!
Tenho uma dúvida para manipular dados da coluna abaixo(os dados formam uma coluna só):
text1 5550 123 444 0,04
text2 text 456 123 445 0,07
text3 text txt 4553 456 456 0,08
text4 454 4555 2122 0,08
Preciso olhando da direita pra esquerda buscar o quarto conjunto de números, resultando em uma nova coluna com os números a seguir:
5550
456
4553
454
Alguem tem alguma sugestão?
Obrigado
clente
2
library(tidyverse)
# Tabela exemplo
df <- tribble(
~coluna,
"text1 5550 123 444 0,04",
"text2 text 456 123 445 0,07",
"text3 text txt 4553 456 456 0,08",
"text4 454 4555 2122 0,08"
)
# Extrair coluna
df %>%
mutate(
numero = str_extract(coluna, "[0-9,.]+(?=(\\s[0-9,.]+){3}$)"),
numero = as.numeric(numero)
)
#> # A tibble: 4 x 2
#> coluna numero
#> <chr> <dbl>
#> 1 text1 5550 123 444 0,04 5550
#> 2 text2 text 456 123 445 0,07 456
#> 3 text3 text txt 4553 456 456 0,08 4553
#> 4 text4 454 4555 2122 0,08 454
Created on 2021-02-02 by the reprex package (v1.0.0)
1 curtida
Valeuuu Caio, me ajudou mtoo!!