Desktop Survival Guide
by Graham Williams

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:

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

Copyright © 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