[R] apply

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Wed Sep 19 15:28:59 CEST 2007


it also works with vectors, e.g.

x <- c("Ca00Mn48_0.gout", "Ca01Mn47_0.gout", "Ca01Mn47_1.gout", 
"Ca48Mn00_0.gout")
substr(x, 3, 4)


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: "Roger Mason" <rmason at esd.mun.ca>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, September 19, 2007 3:03 PM
Subject: [R] apply


> Hello,
>
> I have a list of filenames extracted from a data-frame thus:
>
> files <- main$file
>
> e.g. file[[1]] returns
>
> [1] Ca00Mn48_0.gout
> 4702 Levels: Ca00Mn48_0.gout Ca01Mn47_0.gout Ca01Mn47_1.gout
> ... Ca48Mn00_0.gout
>
> I want to extract the substring that contains the two digits after
> "Ca".  This works on individual entries, e.g. substr(files[[1]],3,4)
> returns "00".
>
> I wish to apply substr() to all the entries in files.  All my 
> efforts
> fail.  Could some kind soul explain how to do what I want?
>
> Thanks,
>
> Roger Mason
>
> ______________________________________________
> 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.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list