[R] Apostrophes in R Commander in recode
dwinsemius at comcast.net
Fri Jul 29 18:18:06 CEST 2011
On Jul 29, 2011, at 11:32 AM, Simon Kiss wrote:
> Dear colleagues,
> I'm using R64 (2.13) on Mac OS 10.6.8 and I've encountered a problem
> with the recode function in Rcommander.
It's probably in a package named 'car'.
> The application cannot deal with apostrpohes ( ' ) do not. I've
> got a factor from the 2008 Canada Election study (highest level of
> schooling) and some of the values include "Bachelor's Degree" , .
> I've troubleshooted (shot?) the recode function for all the levels
> and it's really the apostrophe that is the problem.
> When entering , I get the error message
>  ERROR: Use only double-quotes (" ") in recode directives
Need to escape the single quote:
x <- c("Bachelor's Degree" , "Master's Degree")
recode(x, ' "Bachelor\'s Degree" = 1 ; "Master\'s Degree"= 2')
#  1 2
You might also have tried:
> I see also that the same problem exists in recode from the command
> There are two ways I can solve this myself, but neither are both are
> a bit more complex than the context requires (e.g. exercises for an
> undergraduate class). I can use gsub from the command line to remove
> the apostrophes, or i can import the data file without using value
> labels as factor levels and that would doubtless work. But the
> technical documentation for the CES is very poor; my students would
> have to end up opening up the original .sav file in PASW and hunt
> down what the underlying factor levels refer to in that instance.
> Is there a solution within R Commander?
David Winsemius, MD
West Hartford, CT
More information about the R-help