[R] Q about strsplit and regexp

Gabor Grothendieck ggrothendieck at myway.com
Thu Oct 21 07:45:42 CEST 2004


Liaw, Andy <andy_liaw <at> merck.com> writes:

: > I do not want that empty character in the beginning, but 
: > couldn't figure out
: > how to strip the starting white spaces, other than something 
: > ugly like:
: > 
: > > strsplit(sub("^ +", "", "  a b    c "), " +")
: > [[1]]
: > [1] "a" "b" "c"

: 
: Looks like there's no easier way than to strip the spaces before 
: splitting the fields.  

Here is a way to split it up without first stripping away leading spaces:

  scan(textConnection(" a b    c "), what = "")




More information about the R-help mailing list