Dear Wiza[R]ds, I have a data.frame header that looks like this: v2FfaPre15 v2FfaPre10 v2FfaPre5 v2Ffa2 v2Ffa3 v2Ffa4 I need it to look like this, 15 10 5 2 3 4 i.e., with v2FfaPre and v2Ffa stripped off Any suggestions, Thanks in advance! -- Oscar Oscar A. Linares, MD Translational Medicine Unit LaPlaisance Bay, Bolles Harbor Monroe, Michigan 48161 Department of Medicine, University of Toledo College of Medicine Toledo, OH 43606-3390 Department of Internal Medicine, The Detroit Medical Center (DMC) Harper University Hospital Wayne State University School of Medicine Detroit, Michigan 48201 [[alternative HTML version deleted]]
try this:> x <- c('v2FfaPre15', 'v2FfaPre10', 'v2FfaPre5', 'v2Ffa2', 'v2Ffa3', 'v2Ffa4') > sub("^.*?([0-9]+)$", "\\1", x, perl=TRUE)[1] "15" "10" "5" "2" "3" "4">On Thu, Dec 3, 2009 at 9:00 AM, oscar linares <winsaam at gmail.com> wrote:> Dear Wiza[R]ds, > > I have a data.frame header that looks like this: > > v2FfaPre15 ? ?v2FfaPre10 ? ?v2FfaPre5 ? ?v2Ffa2 ? ?v2Ffa3 ? ?v2Ffa4 > > I need it to look like this, > > 15 ? ?10 ? ?5 ? ?2 ? ?3 ? ? 4 > > i.e., with v2FfaPre and ?v2Ffa stripped off > > Any suggestions, > > Thanks in advance! > > -- > Oscar > Oscar A. Linares, MD > Translational Medicine Unit > LaPlaisance Bay, Bolles Harbor > Monroe, Michigan 48161 > > Department of Medicine, > University of Toledo College of Medicine > Toledo, OH 43606-3390 > > Department of Internal Medicine, > The Detroit Medical Center (DMC) > Harper University Hospital > Wayne State University School of Medicine > Detroit, Michigan 48201 > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Try this: gsub(".*[^0-9]", "", header) On Thu, Dec 3, 2009 at 12:00 PM, oscar linares <winsaam at gmail.com> wrote:> Dear Wiza[R]ds, > > I have a data.frame header that looks like this: > > v2FfaPre15 ? ?v2FfaPre10 ? ?v2FfaPre5 ? ?v2Ffa2 ? ?v2Ffa3 ? ?v2Ffa4 > > I need it to look like this, > > 15 ? ?10 ? ?5 ? ?2 ? ?3 ? ? 4 > > i.e., with v2FfaPre and ?v2Ffa stripped off > > Any suggestions, > > Thanks in advance! > > -- > Oscar > Oscar A. Linares, MD > Translational Medicine Unit > LaPlaisance Bay, Bolles Harbor > Monroe, Michigan 48161 > > Department of Medicine, > University of Toledo College of Medicine > Toledo, OH 43606-3390 > > Department of Internal Medicine, > The Detroit Medical Center (DMC) > Harper University Hospital > Wayne State University School of Medicine > Detroit, Michigan 48201 > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Try this where [0-9]+ matches one or more digits and $ matches the end of string. See http://gsubfn.googlecode.com for more. library(gsubfn) x <- c("v2FfaPre15", "v2FfaPre10", "v2FfaPre5", "v2Ffa2", "v2Ffa3", "v2Ffa4") strapply(x, "[0-9]+$", c, simplify = TRUE) # or if you want a numeric result: strapply(x, "[0-9]+$", as.numeric, simplify = TRUE) On Thu, Dec 3, 2009 at 9:00 AM, oscar linares <winsaam@gmail.com> wrote:> Dear Wiza[R]ds, > > I have a data.frame header that looks like this: > > v2FfaPre15 v2FfaPre10 v2FfaPre5 v2Ffa2 v2Ffa3 v2Ffa4 > > I need it to look like this, > > 15 10 5 2 3 4 > > i.e., with v2FfaPre and v2Ffa stripped off > > Any suggestions, > > Thanks in advance! > > -- > Oscar > Oscar A. Linares, MD > Translational Medicine Unit > LaPlaisance Bay, Bolles Harbor > Monroe, Michigan 48161 > > Department of Medicine, > University of Toledo College of Medicine > Toledo, OH 43606-3390 > > Department of Internal Medicine, > The Detroit Medical Center (DMC) > Harper University Hospital > Wayne State University School of Medicine > Detroit, Michigan 48201 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]