Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extracting information from string and creating new variable

I have a column with big character strings like this:

"[{'tipoTeste': 'RT-PCR', 'estadoTeste': 'Concluído',
'dataColetaTeste': {'__type': 'Date', 'iso': '2021-12-30T03:00:00.000Z'}, 
'resultadoTeste': 'Detectável', 'loteTeste': None, 
'fabricanteTeste': None, 'codigoTipoTeste': '1', 'codigoEstadoTeste': '3', 
'codigoResultadoTeste': '1', 'codigoFabricanteTeste': None}]"

And i want to create another variable called Date with the date information inside this huge string, in this case is 2021-12-30

Im not managing to grep this date information for all rows….

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This would work:

library(stringr)
str_extract_all(str, "[0-9]{4}-[0-9]{2}-[0-9]{2}")
[[1]]
[1] "2021-12-30"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading