I have an interesting (only for me, perhaps :)) question. I have text like:
"abbba"
The question is to find all possible substrings of length n in this string. For example, if n = 2, substrings
'ab','bb','ba'
and if n = 3, substrings
'abb','bbb','bba'
I was thinking of using something like this:
x <- 'abbba'
m <- matrix(strsplit(x, '')[[1]], nrow=2)
apply(m, 2, paste, collapse='')
But I have a warning, and it does not work for len = 3.
source
share