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 Rfunction[]gsub:



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



Copyright © 2004-2009 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
PDF version is properly formatted and forms a comprehensive book (draft with over 700 pages).
Brought to you by Togaware. This page generated: Tuesday, 06 January 2009