Skip to content

Instantly share code, notes, and snippets.

@earino
Created January 6, 2014 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earino/8276241 to your computer and use it in GitHub Desktop.
Save earino/8276241 to your computer and use it in GitHub Desktop.
R native string slice implementation.
s <- "some source text..."
cutpoints <-data.frame(start=text$start, end=text$end)
keeps <- data.frame(start=c(1, cutpoints$end+1), end=c(cutpoints$start-1, nchar(s)))
pieces <- apply(keeps, 1, function(x) substr(s, x[1], x[2]))
sliced_string <- paste(pieces, collapse="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment