Re: [R] splitting a vector of strings

2016-07-21 Thread Michael Dewey
Dear Eric I think you are looking for sub or gsub Without an example set of input and output I am not quite sure but you would need to define an expression which matches your separator (;) followed by any characters up to the end of line. If you have trouble with that then someone here will n

Re: [R] splitting a vector of strings

2016-07-21 Thread Ben Tupper
Hi, I'm not sure about the more generalized solution, but how about this for a start. x <- c("a;b;c", "d;e", "foo;g;h;i") x #[1] "a;b;c" "d;e" "foo;g;h;i" sapply(strsplit(x, ";",fixed = TRUE), '[',1) #[1] "a" "d" "foo" If you want elegance then I suggest you take a look at the s

Re: [R] splitting a vector of strings...

2009-10-22 Thread andrew
the following works - double backslash to remove the "or" functionality of | in a regex. (Bill Dunlap showed that you don't need sapply for it to work) xs <- "this is | string" xsv <- paste(xs, 1:10) strsplit(xsv, "\\|") On Oct 23, 3:50 pm, Jonathan Greenberg wrote: > William et al: > >     Th

Re: [R] splitting a vector of strings...

2009-10-22 Thread Jonathan Greenberg
William et al: Thanks! I think I have a somewhat more complicated issue due to the type of string I'm using -- the split is " | " (space pipe space) -- how do I code that based on your sub code below? Using " | *" doesn't seem to be working. Thanks! --j William Dunlap wrote: -Ori

Re: [R] splitting a vector of strings...

2009-10-22 Thread andrew
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 wrote: > Quick question -- if I have a vector of s

Re: [R] splitting a vector of strings...

2009-10-22 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Greenberg > Sent: Thursday, October 22, 2009 7:35 PM > To: r-help > Subject: [R] splitting a vector of strings... > > Quick question -- if I have a vector of strings tha