How to split a character vector based on a numeric vector for positions

Viewed 1290

I would like to split a character vector into substrings based on a second numeric vector for the splitting points

vec <- "LAYRVCMTNEGHPWVSLVVQKTRLQISQDPSLNYEYLPTMGLKSFIQASLALLFGKHSQAIVENRVGGVHTVGDSGAFQLGVQFLRAWHKDARIVYIISSQKELHGLVFQDMGFTVYEYSVWDPKKLCMDPDILLNVVEQIPHGCVLVMGNIIDCKLTPSGWAKLMSM"
split.points <- c(25, 32, 55, 90, 124)

I would like to cut the above character vector at the positions given in the split.points vector into six different substrings.

It sounds very simple, but the split command I know works either only with specific regex (patterns) or with a set length of substrings.

I would appreciate any help.

3 Answers
Related