Re: [R] numbers as part of long character

From: Charilaos Skiadas <>
Date: Thu, 12 Jun 2008 18:52:20 -0400

On Jun 12, 2008, at 6:34 PM, Hua Li wrote:

> Thanks, Marc and Haris!
> I didn't know the values of the numbers beforehand, so the scan
> method won't work, but "[^+-\\d.]+" will do!
> And Haris, I didn't intend to keep the information of which number
> is B, which is C etc when asking the question, as I had a tedious
> way to do it (use strspilt and unlist over and over again, after I
> get the number). But if you have a easier way to do it, I'd like to
> know!

Depending on how your real use case looks like, the following might work:

vec1 <- strsplit(, "[^+-\\d.:\\w]+", perl=TRUE)[[1]] nums <- as.numeric(gsub("\\w?:","", vec1, perl=TRUE)) names(nums) <- gsub(":[+-\\d.]+","", vec1, perl=TRUE)

If it doesn't, then provide us with the example that fails it.

> Hua

Haris Skiadas
Department of Mathematics and Computer Science Hanover College mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 13 Jun 2008 - 00:14:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 Jun 2008 - 00:31:03 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive