[R] splitting a vector of strings...

andrew andrewjohnroyal at gmail.com
Fri Oct 23 05:14:34 CEST 2009

xs <- "this is string"
xsv <- paste(xs, 1:10)
sapply(xsv, function(x) strsplit(x, '\\sis\\s'))

This will split the vector of string "xsv" on the word 'is' that has a
space immediately before and after it.

On Oct 23, 1:34 pm, Jonathan Greenberg <greenb... at ucdavis.edu> wrote:
> Quick question -- if I have a vector of strings that I'd like to split
> into two new vectors based on a substring that is inside of each string,
> what is the most efficient way to do this?  The substring that I want to
> split on is multiple characters, if that matters, and it is contained in
> every element of the character vector.
> --j
> --
> Jonathan A. Greenberg, PhD
> Postdoctoral Scholar
> Center for Spatial Technologies and Remote Sensing (CSTARS)
> University of California, Davis
> One Shields Avenue
> The Barn, Room 250N
> Davis, CA 95616
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn... at hotmail.com, Gchat: jgrn307
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list