Re: [R] Extracting only one part of an string

2007-11-19 Thread Gabor Grothendieck
Just replace the minus and everything after it with an empty string: sub("-.*", "", Names) On Nov 19, 2007 2:14 AM, Tom.O <[EMAIL PROTECTED]> wrote: > > Hi > I wonder if there's a smarter way to do this procedure. > > I have a vector of filenames wher I only am interested in the first part of

Re: [R] Extracting only one part of an string

2007-11-19 Thread Prof Brian Ripley
On Mon, 19 Nov 2007, Benilton Carvalho wrote: > I'd use: > > sapply(strsplit(Names, "-"), "[[", 1) An alternative is sub("([^-]*).*", "\\1", Names) which for many Names would be considerably more efficient. > On Nov 19, 2007, at 2:14 AM, Tom.O wrote: > >> >> Hi >> I wonder if there's a smarte

Re: [R] Extracting only one part of an string

2007-11-18 Thread Benilton Carvalho
I'd use: sapply(strsplit(Names, "-"), "[[", 1) b On Nov 19, 2007, at 2:14 AM, Tom.O wrote: > > Hi > I wonder if there's a smarter way to do this procedure. > > I have a vector of filenames wher I only am interested in the first > part of > the filename. > I would use the following method of

[R] Extracting only one part of an string

2007-11-18 Thread Tom.O
Hi I wonder if there's a smarter way to do this procedure. I have a vector of filenames wher I only am interested in the first part of the filename. I would use the following method of extracting the first part. But is there a more simple way of doing this? Names <- c("A1-F1.txt","A2-F1.txt","A