How do I split column a (by the space character) and count how many times any of the substrings in column a exist in column b?
library(data.table)
library(stringr)
dt = data.table(
a = c('one', 'one two', 'one two three'),
b = c('zero', 'none_or One?' , 'onetwothree')
)
I failed when I tried:
dt[ , .(
str_count( b,
pattern = str_split( a , pattern = ' ' )
)
) ]
Error in UseMethod("type") :
no applicable method for 'type' applied to an object of class "list"
I expect:
V1
1: 0
2: 1
3: 3