Searching for specific names within lines

Asked

Viewed 48 times

0

I have a database about parties and on one line I have a series of acronym like: PT/PSDC/PCB/PMDB. How do I select only the PMDB within those lines?

  • You need to post a sample from your database, so we can understand what kind of data we’re dealing with, without that information there’s no way to do anything.

1 answer

1


You can do it:

partido<-c('PT/PSDC/PCB/PMDB')

library(stringr)
str_extract(partido,'PMDB')

This function extracts the first element found (in this case, only a unit of PMDB). If there are several PMDBs inside the vector, use str_extract_all to extract all acronyms PMDB:

str_extract_all(partido,'PMDB')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.