[R] removing contractions for recode in car

Nicole Marie Ford nmford at uwm.edu
Fri Dec 16 19:01:18 CET 2011


I see the problem.  So Sorry.
 

----- Original Message -----
From: "Nicole Marie Ford" <nmford at uwm.edu>
To: "John Fox" <jfox at mcmaster.ca>
Cc: r-help at r-project.org
Sent: Friday, December 16, 2011 11:54:36 AM
Subject: Re: [R] removing contractions for recode in car

Hello, all.

I am encountering a new problem I have not seen before.

I recoded my variable trust in the following manner (thank you John and David):

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")

when I examine the variable, I find the following:


> levels(Poland$trust)
[1] "1" "2" "3" "4" "6"

level 5 is missing.

i check again here:


> levels(Poland$SN35B)
[1] "NAP:NOT ASKED/BALOT"        "Strongly Agree"             "Agree"                     
[4] "Neither Agree nor Disagree" "Disagree"                   "Cant choose"               
[7] "Can't choose"               "NO ANSWER"        


yes, 5 should be "Disagree".


So I check to be sure people did answer "Disagree".  I find they did:

> summary(Poland$SN35B)
       NAP:NOT ASKED/BALOT             Strongly Agree                      Agree 
                     12443                         83                        545 
Neither Agree nor Disagree                   Disagree                Cant choose 
                       306                        183                         29 
              Can't choose                  NO ANSWER 
                        62                         13 

I was wondering if anyone has any ideas as to why my 5th choice might be missing after I recode?

Thanks.

~Nicole



----- Original Message -----
From: "Nicole Marie Ford" <nmford at uwm.edu>
To: "John Fox" <jfox at mcmaster.ca>
Cc: r-help at r-project.org
Sent: Thursday, December 15, 2011 3:39:01 PM
Subject: Re: [R] removing contractions for recode in car

Dear John and David,

Thanks so much for the advice.  I have only come across this one other time in my research, so the code escaped me!  Much obliged!

~Nicole

Ph.D. Student 
University of Wisconsin Milwaukee 
c: 813.786.5715 
e: nmford at uwm.edu 

----- Original Message -----
From: "John Fox" <jfox at mcmaster.ca>
To: "Nicole Marie Ford" <nmford at uwm.edu>
Cc: r-help at r-project.org
Sent: Thursday, December 15, 2011 3:16:58 PM
Subject: Re: [R] removing contractions for recode in car

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.

______________________________________________
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