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
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
Hi everybody,
I have a vector of character strings.
Each string has the same pattern and I want
to split them in pieces and get a vector made
of the first pieces of each string.
The problem is that strsplit returns a list.
All I found is
uu<- matrix(unlist(strsplit(x,";")),ncol=3,byrow=T)[,1]
eem
> to be working. Thanks!
>
> --j
>
>
>
> William Dunlap wrote:
> >> -Original Message-
> >> From: r-help-boun...@r-project.org
> >> [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Greenberg
> >> Sent: Thursday, October
s!
--j
William Dunlap wrote:
-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 s
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
> -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
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
8 matches
Mail list logo