Message-ID: <CAM_vjukSq2erb8R3UMQAhu-ZcsKkM_NVsZTqdOdwdU+E1RujQw@mail.gmail.com>
Date: 2012-07-16T19:36:27Z
From: Sarah Goslee
Subject: extract number from a mixture of character and number
In-Reply-To: <1342454664529-4636659.post@n4.nabble.com>
Hi,
There are lots; the best choice depends on whether your ID values
always start with "sub_" or not, and you aren't clear. Here's a
general case:
testdata <- c("sub_001", "sub_002", "sub_003")
gsub("[^0-9]", "", testdata)
You can use as.numeric() to convert them if desired.
If you use dput() to provide your data, someone might give you actual
working code.
Sarah
On Mon, Jul 16, 2012 at 12:04 PM, york8866 <yu_york at hotmail.com> wrote:
> Hi, all,
>
> I have a column like the following:
> ID TIME
> sub_001 0
> sub_001 24
> sub_002 0
> sub_002 24
> sub_003 0
> sub_003 24
> sub_004 0
> sub_005 24
> ..
> ..
>
> is there a way for me to just extract the numeric numbers from the ID
> column, omitting sub_?
>
> thanks,
>
>
--
Sarah Goslee
http://www.functionaldiversity.org