[R] about string

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 6 11:30:22 CEST 2006


On Tue, 6 Jun 2006, Dimitris Rizopoulos wrote:

> try the following:
>
> strg <- "abc"
> nchar(strg)
> ############
> strg <- c("f:\\JPCS_signal.txt", "f:\\PC1_signal.txt",
>          "f:\\PC2_signal.txt")
> strg. <- sapply(strsplit(strg, "\\\\"), "[", 2)
> sapply(strsplit(strg., "_"), "[", 1)

or (a bit simpler)

> gsub("f:\\\\([^_]*).*", "\\1", strg)
[1] "JPCS" "PC1"  "PC2"


>
>
> I hope it helps.
>
> Best,
> Dimitris
>
> ----
> Dimitris Rizopoulos
> Ph.D. Student
> Biostatistical Centre
> School of Public Health
> Catholic University of Leuven
>
> Address: Kapucijnenvoer 35, Leuven, Belgium
> Tel: +32/(0)16/336899
> Fax: +32/(0)16/337015
> Web: http://med.kuleuven.be/biostat/
>     http://www.student.kuleuven.be/~m0390867/dimitris.htm
>
>
> ----- Original Message -----
> From: "XinMeng" <xmeng at capitalbio.com>
> To: <r-help at stat.math.ethz.ch>
> Sent: Tuesday, June 06, 2006 10:40 AM
> Subject: [R] about string
>
>
>> Hello sir:
>> There are 2 questions about string.
>> 1 How to calculate the width of a string? e.g string "abc"'s width
>> is 3;
>> 2 How can I get the "substring" in such kind of condition:
>>  "f:\\JPCS_signal.txt"  "f:\\PC1_signal.txt" "f:\\PC2_signal.txt"
>> What I wanna get is "JPCS"  "PC1"  "PC2".How can I achieve them by R
>> cammand?
>>
>> Thanks a lot!
>>
>> My best
>>
>>
>>
>>
>> ------------------------------
>> *******************************************
>> Xin Meng
>> Capitalbio Corporation
>> National Engineering Research Center
>> for Beijing Biochip Technology
>> BioPharma-informatics & Software Dept.
>> Research Engineer
>> Tel: +86-10-80715888/80726868-6438
>> Fax: +86-10-80726790
>> Email£ºxmeng at capitalbio.com
>> Address:18 Life Science Parkway,
>> Changping District, Beijing 102206, China
>>
>>
>
>
> --------------------------------------------------------------------------------
>
>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list