I have two vectors:
- Vector text
c('abc', 'asdf', 'werd', 'ffssd') - Vector Templates
c('ab', 'd', 'w')
I would like to digitize the following for-loop:
for(p in 1 : length(patterns)){
count <- count + str_count(texts, p);
}
I used the following commands, but both of them will not work.
> str_count(texts, patterns)
[1] 1 1 1 0
Warning message:
In stri_count_regex(string, pattern, opts_regex = attr(pattern, :
longer object length is not a multiple of shorter object length
> str_count(texts, t(patterns))
[1] 1 1 1 0
Warning message:
In stri_count_regex(string, pattern, opts_regex = attr(pattern, :
longer object length is not a multiple of shorter object length
I need a 2d matrix:
| patterns
------+--------
| 1 0 0
texts | 0 1 0
| 0 1 1
| 0 1 0
source
share