Re: [R] Removing a dollar sign from a character vector

2016-02-11 Thread Jeff Newmiller
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. --

Re: [R] Removing a dollar sign from a character vector

2016-02-11 Thread William Dunlap via R-help
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

Re: [R] Removing a dollar sign from a character vector

2016-02-11 Thread William Dunlap via R-help
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'.

Re: [R] Removing a dollar sign from a character vector

2016-02-10 Thread William Dunlap via R-help
> 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

Re: [R] Removing a dollar sign from a character vector

2016-02-10 Thread Jeff Newmiller
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