[R] splitting a string up

Bert Gunter gunter.berton at gene.com
Fri Aug 21 22:01:32 CEST 2009


Actually "_" is not a metacharacter so, gsub("_.*","",x) will do.

Bert Gunter
Genentech Nonclinical Biostatisics


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Doran, Harold
Sent: Friday, August 21, 2009 12:55 PM
To: stephen sefick; r-help at r-project.org
Subject: Re: [R] splitting a string up

> x <- "1041281__2009_08_20_.lev"
> strsplit(x, '_')[[1]][1]
[1] "1041281" 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of stephen sefick
> Sent: Friday, August 21, 2009 3:51 PM
> To: r-help at r-project.org
> Subject: [R] splitting a string up
> 
> x <- "1041281__2009_08_20_.lev"
> 
> I would like to split this string up and only extract the 
> leading numbers.
> 
> 1041281
> 
> to use as a label for a data column in a bigger for loop 
> function to read in data.
> regards,
> 
> --
> Stephen Sefick
> 
> Let's not spend our time and resources thinking about things 
> that are so little or so large that all they really do for us 
> is puff us up and make us feel like gods.  We are mammals, 
> and have not exhausted the annoying little problems of being mammals.
> 
> 								
> -K. Mullis
> 
> ______________________________________________
> 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.
> 

______________________________________________
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.




More information about the R-help mailing list