How can I output the matches found in a new dataframe column?

Viewed 19

I have in variable ticker about 7000 different stock symbols that I would like to find in posts$title of a dataframe.

Example:

ticker <-c('AMZN','TSLA','VAR','DAX')

The dataframe contains 2 columns: id, title

In title are different texts about stocks. The goal is to identify the tickers of these stocks and list them in a new column. In each case in the row of the text.

This code block unfortunately only returns the entire list of text in which a ticker was found. However, I need this as described above.

grep(paste0('\\b',ticker,'\\b', collapse="|"), posts$title, ignore.case = FALSE, value = TRUE)

I hope someone here can help.

0 Answers
Related