Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Trim Whitespace

A simple function to trim whitespace from the beginning and end of a string, which you could then use to more simply split a string into a vector, uses gsub:



> trim.ws <- function(text) 
+            gsub("^[[:blank:]]*", "", gsub("[[:blank:]]*$", "", text))
> s <- "  a b    c "
> strsplit(trim.ws(s), " +")
[1] "a" "b" "c"



Copyright © 2004-2006 Graham.Williams@togaware.com
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.