[R] looking for one-liner for strsplit and regex

David Winsemius dwinsemius at comcast.net
Sun Apr 12 03:51:27 CEST 2009


What you have now is a list with one element which happens to be a  
character vector. Try:

 > vec <- scan(textConnection(myline))
Read 5 items
 > vec
[1]   0.100000   1.500000   0.600000 538.000000   0.369404


-- 
David Winsemius
On Apr 11, 2009, at 8:23 PM, Juliet Hannah wrote:

> Hi,
>
> I have a line such as:
>
> myline <-  "    0.100000      1.5000      0.6000                 538
> 0.369404"
>
> and I would like to put the numbers into a vector. Some combination of
> tabs and spaces occur between the numbers.
>
> I tried:
>
> try1 <- strsplit(myline,"[[:blank:]]+")
>> try1
> [[1]]
> [1] ""         "0.100000" "1.5000"   "0.6000"   "538"      "0.369404"
>
> The first element is "", which I do not want. I can get rid of the
> "", but I was wondering if someone can show me the proper way to do
> this in 1 line.
>
> Thanks,
>
> Juliet
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list