[R] Extracting only one part of an string

Tom.O tom.olsson at dnbnor.com
Mon Nov 19 08:14:44 CET 2007


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","AB1-F1.txt","A1-F2.txt","AB1-F2.txt","B1-F2.txt")
#..
temp <- strsplit(Names,"-")
temp <- unlist(temp)
temp <- temp[seq(from=1,to=2*length(Names),by=2)]

> temp
[1] "A1"  "A2"  "AB1" "A1"  "AB1" "B1" 

Thanks for any feedback.
Regards Tom
-- 
View this message in context: http://www.nabble.com/Extracting-only-one-part-of-an-string-tf4833641.html#a13828611
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list