Hello again! I have a set of character results. If one of the characters is a blank space, followed by other characters, I want to end at the blank space. I tried strsplit, but it picks up again after the blank. Any help would be much appreciated. TIA, Edna
Is this what you want?> a<-c("a b c","1 2 3","q - 5") > a[1] "a b c" "1 2 3" "q - 5"> sapply(strsplit(a,"[[:blank:]]"),function(x)x[1])[1] "a" "1" "q" Edna Bell wrote:> > I have a set of character results. If one of the characters is a > blank space, followed by other characters, I want to end at the blank > space. > > I tried strsplit, but it picks up again after the blank. > > Any help would be much appreciated. >-- View this message in context: http://www.nabble.com/substrings-tf4241506.html#a12069209 Sent from the R help mailing list archive at Nabble.com.
one more, shorter, solution.> a[1] "a b c" "1 2 3" "q- 5"> gsub("\\s.+","",a)[1] "a" "1" "q-" Edna Bell wrote:> > I have a set of character results. If one of the characters is a > blank space, followed by other characters, I want to end at the blank > space. > > I tried strsplit, but it picks up again after the blank. > > Any help would be much appreciated. >-- View this message in context: http://www.nabble.com/substrings-tf4241506.html#a12069488 Sent from the R help mailing list archive at Nabble.com.