I am trying to extract all strings from rows in a dataframe that match certain criteria for example how many words are match 'corn' in each row. Here is the input.
install.packages('stringr')
library(stringr)
dataset <- c("corn", "cornmeal", "corn on the cob", "meal")
y<- c('corn',"corn","mean","meal")
id<- c(1,2,3,4)
dataset <- data.frame(id,dataset,y)
id dataset y
1 1 corn corn
2 2 cornmeal corn
3 3 corn on the cob mean
4 4 meal meal
I am trying to get output like this
id dataset y corn meal
1 1 corn corn 2 0
2 2 cornmeal corn 1 0
3 3 corn on the cob mean 0 0
4 4 meal meal 0 2