I have a tidyr function (if it can me solved here would be great) which takes a data.table object and sees if a keyword (kw - here it is 'agree') is mentioned any times. This returns me a data.table vector of lists with anytime it mentions it:
test <- ptadfmatching[,"text"] %>%
mutate(new_var = str_extract_all(text, regex(kw[x], ignore_case = TRUE)) )%>%
select(new_var)
The result is something like this
> test
new_var
<list>
1: AGREE,Agree,agree
2: Agree,Agree,Agree
3: agree,Agree
4: agree,Agree
5: Agree
6: agree
7: Agree,Agree
8: Agree,Agree,Agree
9: Agree,Agree,agree
10:
Question - how do I get length of each list in 'test' (without a loop).