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
, the substrings are
'ab','bb','ba'
and if n = 3
, the substrings are
'abb','bbb','bba'
I thought to use something like this:
x <- 'abbba'
m <- matrix(strsplit(x, '')[[1]], nrow=2)
apply(m, 2, paste, collapse='')
But I got a warning and it doesn't work for len = 3.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…