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...@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...@hotmail.com, Gchat: jgrn307 > > ______________________________________________ > r-h...@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. ______________________________________________ R-help@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.