简体   繁体   中英

Convert character vector to data.frame after str_extract()

I have a dataframe:

head(objeto)
                                                      Edital
1                          GOVERNO DO ESTADO DE MINAS GERAIS
2 SECRETARIA-GERAL DA GOVERNADORIA DO ESTADO DE MINAS GERAIS
3                         EDITAL DA CONCORRÊNCIA Nº 001/2012
4                                        EDITAL DE LICITAÇÃO
5                                  CONCORRÊNCIA Nº. 001/2012
6                                      TIPO: TÉCNICA E PREÇO

I want to find the regex "Objeto" in it, so:

regex.objeto <- "(?<=Objeto: )([^.]+)"
objeto <- str_extract(edital, regex.objeto)

objeto

[1] "CONTRATAÇÃO DE EMPRESA PARA A PRESTAÇÃO DE SERVIÇOS\", \"ESPECIALIZADOS DE AFERIÇÃO DO DESEMPENHO E DA QUALIDADE DA\", \"CONCESSIONÁRIA MINAS ARENA GESTÃO DE INSTALAÇÕES ESPORTIVAS\", \n\"S"

The result is a character vector, but I would like to have a dataframe, without these symbols \", \

I was thinking the result something like this:

"CONTRATAÇÃO DE EMPRESA PARA A PRESTAÇÃO DE SERVIÇOS ESPECIALIZADOS DE AFERIÇÃO DO DESEMPENHO E DA QUALIDADE DA"

Thank you all!

Maybe you can use gsub to remove double quotes from the string and "\n" .

objeto <- gsub('"|\n|,', '', objeto)

which returns:

objeto
#[1] "CONTRATAÇÃO DE EMPRESA PARA A PRESTAÇÃO DE SERVIÇOS ESPECIALIZADOS DE AFERIÇÃO DO DESEMPENHO E DA QUALIDADE DA CONCESSIONÁRIA MINAS ARENA GESTÃO DE INSTALAÇÕES ESPORTIVAS S"

This can also be written as:

objeto <- gsub('["\n,]', '', objeto)

Or using str_remove_all from stringr library

stringr::str_remove_all(objeto, '[\n",]')

which is a shortcut for str_replace_all

stringr::str_replace_all(objeto, '[\n",]', '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM