Re: [R] splitting a string up

2009-08-21 Thread Marc Schwartz
Just be aware that this only works if 'x' contains a single entry. If 'x' is a vector of multiple such entries, you will only get the leading numbers in the first entry: x2 <- c(x, x) > x2 [1] "1041281__2009_08_20_.lev" "1041281__2009_08_20_.lev" > strsplit(x2, split="_")[[1]][1] [1] "1041

Re: [R] splitting a string up

2009-08-21 Thread Stephan Kolassa
strsplit("1041281__2009_08_20_.lev", split="_")[[1]][1] HTH, Stephan stephen sefick schrieb: 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. r

Re: [R] splitting a string up

2009-08-21 Thread Marc Schwartz
On Aug 21, 2009, at 2:50 PM, stephen sefick wrote: 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, At least four options: > gsu

Re: [R] splitting a string up

2009-08-21 Thread Bert Gunter
21, 2009 12:55 PM To: stephen sefick; r-help@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-boun...@r-project.org > [mailto:r-

Re: [R] splitting a string up

2009-08-21 Thread Henrique Dallazuanna
Try this: gsub("__.*", "", "1041281__2009_08_20_.lev") On Fri, Aug 21, 2009 at 4:50 PM, stephen sefick wrote: > 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

Re: [R] splitting a string up

2009-08-21 Thread Bert Gunter
Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of stephen sefick Sent: Friday, August 21, 2009 12:51 PM To: r-help@r-project.org Subject: [R] splitting a string up x <- "1041281__2009_08_20_.lev" I would like to split this string up and

Re: [R] splitting a string up

2009-08-21 Thread Doran, Harold
09 3:51 PM > To: r-help@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 bigg

[R] splitting a string up

2009-08-21 Thread stephen sefick
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 ar