Re: [R] numbers as part of long character

From: Charilaos Skiadas <cskiadas_at_gmail.com>
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(outtree.new, "[^+-\\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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive