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 are
x - 1041281__2009_08_20_.lev
strsplit(x, '_')[[1]][1]
[1] 1041281
-Original 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 3:51 PM
To: r-help@r-project.org
Subject: [R] splitting
-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 only extract the leading numbers.
1041281
to use
Try this:
gsub(__.*, , 1041281__2009_08_20_.lev)
On Fri, Aug 21, 2009 at 4:50 PM, stephen sefick ssef...@gmail.com 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
-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-help-boun...@r-project.org] On Behalf Of stephen sefick
Sent: Friday, August 21, 2009 3:51 PM
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:
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] 1041281
as
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.
8 matches
Mail list logo