I should have said that R-3.2.3 requires the $ to be backslashed even when
it
is not at the end of the pattern:
> gsub("$[[:digit:]]*", "", c("$VAR", "$20/oz."))
[1] "$VAR""$20/oz."
> gsub("\\$[[:digit:]]*", "", c("$VAR", "$20/oz."))
[1] "VAR" "/oz."
Modern Linuxen's tools like sed d
In certain programs (not current R), a pattern with stuff after a naked
dollar
sign would not match anything because dollar meant end-of-string.
In any case I prefer simple rules like 'backslash a dollar sign' instead of
'backslash a dollar sign at the end of the pattern but not elsewhere'.
Bill
The "end of string" special meaning only applies when the dollar sign is at the
right end of the string (as it was in the OP attempt). That is, it is NOT
generally necessary to wrap it in brackets to remove the special meaning unless
it would otherwise be at the end of the pattern string.
--
> y
[1] "$1,000.00 " "$1,000.00 " "$1,000.00 " "$2,600.00 " "$2,600.00 "
> gsub("$", "", y)
[1] "$1,000.00 " "$1,000.00 " "$1,000.00 " "$2,600.00 " "$2,600.00 “ #
no change. Why?
"$" as a regular expression means "end of string", which has zero length -
replacing "end
of string" with n
y <- as.numeric( gsub( "[$, ]", "", y ) )
--
Sent from my phone. Please excuse my brevity.
On February 10, 2016 9:39:16 PM PST, James Plante wrote:
>What I’ve got:
># sessionInfo()
>R version 3.2.3 (2015-12-10)
>Platform: x86_64-apple-darwin13.4.0 (64-bit)
>Running under: OS X 10.11.3 (El Capita
What I’ve got:
# sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.3 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets
6 matches
Mail list logo