[R] removing contractions for recode in car

John Fox jfox at mcmaster.ca
Thu Dec 15 22:16:58 CET 2011


Dear Nicole,

On Thu, 15 Dec 2011 14:49:04 -0600 (CST)
 Nicole Marie Ford <nmford at uwm.edu> wrote:
> hello,
> 
> i need to recode a variable, however the contraction is causing problems.  i had the code to change this written down somewhere and i just can't find it, of course.
> 
> i am using the car library to recode.
> 
> it's only 5 levels when it should have 6... when i do levels(trust).
> 
> here is my recode: 
> 
> 
> trust <- recode(Poland$SN35B, " 'Strongly Agree' = 1; 'Agree' = 2; 'Neither Agree nor Disagree' = 3; 'Disagree' = 4; 'Strongly Disagree' = 5; 'Can't choose' = 6; else=NA")

Although it's awkward, you should be able to do what you want by "escaping" the quotation marks surrounding the level name; the following (untested) should work:

trust <- recode(Poland$SN35B, " 'Strongly Agree' = 1; 'Agree' = 2; 'Neither Agree nor Disagree' = 3; 'Disagree' = 4; 'Strongly Disagree' = 5; \"Can't choose\" = 6; else=NA")

I hope this helps,
 John

------------------------------------------------
John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

> 
> 
> thanks.
> 
> ~nicole
> ----- Original Message -----
> From: "David Winsemius" <dwinsemius at comcast.net>
> To: "Rui Barradas" <ruipbarradas at sapo.pt>
> Cc: r-help at r-project.org
> Sent: Thursday, December 15, 2011 2:33:32 PM
> Subject: Re: [R] printing all htest class members
> 
> 
> On Dec 15, 2011, at 2:16 PM, Rui Barradas wrote:
> 
> > You're right, David,
> >
> > The first line is wrong, it should be
> >
> > ...  df=2:4  ...
> >
> > As for creating something, try
> >
> >> ht <- structure( ... etc ...
> >> ht
> >> class(ht)
> >
> > See what is printed and what function prints it.
> 
> Well, the function is stats:::print.htest.
> 
> (Do not expect any further replies to emails sent without context.)
> 
> #---------------------------------------------------#
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> #---------------------------------------------------#
> >
> 
> David Winsemius, MD
> West Hartford, CT
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list