[R] break up a string into strings with a fixed length

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 2 13:58:37 CEST 2009


Try this:

> library(gsubfn)
> s <- "abcdefghijkl"

> strapply(s, "...")[[1]]
[1] "abc" "def" "ghi" "jkl"


On Fri, Oct 2, 2009 at 5:36 AM, J Chen <jiaxuan.chen at mdc-berlin.de> wrote:
>
> dear all,
>
> I have some very long strings and would like to break up each long string
> into multiple strings with a fixed length, e.g. to break up
>
> abcdefghijkl
>
> into
>
> abc, def, ghi, jkl
>
> I tried a couple of commands but was not successful. Any help will be
> appreciated.
>
> Best,
> Jimmy
> --
> View this message in context: http://www.nabble.com/break-up-a-string-into-strings-with-a-fixed-length-tp25712955p25712955.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list