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-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010