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
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,
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
3 matches
Mail list logo