Just be aware that this only works if 'x' contains a single entry. If
'x' is a vector of multiple such entries, you will only get the
leading numbers in the first entry:
x2 <- c(x, x)
> x2
[1] "1041281__2009_08_20_.lev" "1041281__2009_08_20_.lev"
> strsplit(x2, split="_")[[1]][1]
[1] "1041
strsplit("1041281__2009_08_20_.lev", split="_")[[1]][1]
HTH,
Stephan
stephen sefick schrieb:
x <- "1041281__2009_08_20_.lev"
I would like to split this string up and only extract the leading numbers.
1041281
to use as a label for a data column in a bigger for loop function to
read in data.
r
On Aug 21, 2009, at 2:50 PM, stephen sefick wrote:
x <- "1041281__2009_08_20_.lev"
I would like to split this string up and only extract the leading
numbers.
1041281
to use as a label for a data column in a bigger for loop function to
read in data.
regards,
At least four options:
> gsu
21, 2009 12:55 PM
To: stephen sefick; r-help@r-project.org
Subject: Re: [R] splitting a string up
> x <- "1041281__2009_08_20_.lev"
> strsplit(x, '_')[[1]][1]
[1] "1041281"
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-
Try this:
gsub("__.*", "", "1041281__2009_08_20_.lev")
On Fri, Aug 21, 2009 at 4:50 PM, stephen sefick wrote:
> x <- "1041281__2009_08_20_.lev"
>
> I would like to split this string up and only extract the leading numbers.
>
> 1041281
>
> to use as a label for a data column in a bigger for loop
Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of stephen sefick
Sent: Friday, August 21, 2009 12:51 PM
To: r-help@r-project.org
Subject: [R] splitting a string up
x <- "1041281__2009_08_20_.lev"
I would like to split this string up and
09 3:51 PM
> To: r-help@r-project.org
> Subject: [R] splitting a string up
>
> x <- "1041281__2009_08_20_.lev"
>
> I would like to split this string up and only extract the
> leading numbers.
>
> 1041281
>
> to use as a label for a data column in a bigg
x <- "1041281__2009_08_20_.lev"
I would like to split this string up and only extract the leading numbers.
1041281
to use as a label for a data column in a bigger for loop function to
read in data.
regards,
--
Stephen Sefick
Let's not spend our time and resources thinking about things that ar
8 matches
Mail list logo