I am working with long texts from the newspapers texts and I want
to create new variables to codify some topics of the news.
For example, if the content of the title refers to labor or an educational issue.
I want to codify every new with an 'issue' variable containing 'labor' or 'education' as categories.
news_DF <- tibble(newspaper=c('New York Times', 'Washington Post', 'The Times', 'The Times'),
title=c('Workers are striking all over the world',
'Workers are not striking in March 2009',
'The scholarship students in America are not well paid',
'The US employees are not part of the working class'))
The words referring to the 'labor' type of issue can be:
labor_vector <- c('workers', 'teachers', 'employees', 'unions', 'AFL-CIO')
How I do that without writing every single element of a long list of words-
as the code below- but using vectors like the 'labor_vector'?
news_DF2 <- news_DF %>%
mutate(isse = case_when
(str_detect(title, 'Workers') ~ 'labor',
str_detect(title, 'employees') ~ 'labor',
str_detect(title, 'students') ~ 'education'))