[R] Remove a word from a character vector value XXXX

2012-03-07 Thread Dan Abner
Hi everyone, What is the easiest way to remove the word Average and strip leading and trailing blanks from the character vector (d5.Region) below? .nrow.d5. d5.Region 11 Central Average 22 Coastal Average 33East Average 44

Re: [R] Remove a word from a character vector value XXXX

2012-03-07 Thread Justin Haynes
Hadley's package stringr is wonderful for all things string. library(stringr) ?str_trim and ?str_replace are what you want. (the base R equivalent of these two would be ?gsub and some regular expressions) str_trim(str_replace(d5.Region, 'Average', '')) should do the trick. hope that helps,

Re: [R] Remove a word from a character vector value XXXX

2012-03-07 Thread David Winsemius
On Mar 7, 2012, at 11:03 AM, Dan Abner wrote: Hi everyone, What is the easiest way to remove the word Average and strip leading and trailing blanks from the character vector (d5.Region) below? .nrow.d5. d5.Region 11 22 Coastal Average 33