r - Splitting a string using variable offset -


i want substrings of size n , and offset o string.

for example, given "abcdef" , substrings of size = 3, offset = 1. want obtain set "abc","bcd", "cde", "def".

in mathematica, can done partition or stringpartition.

is there similar function in r?

you can write wrapper (thanks @thelatemail):

subs = function(x, size, offset){   nc    = nchar(x)   first = seq(1, nc-size+1l, by=offset)   last  = first + size -1l   substring(x, first, last) }   subs("abcde",3, 1) [1] "abc" "bcd" "cde" 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -