Re: [R] Recoding a variable

From: John Fox <jfox_at_mcmaster.ca>
Date: Thu, 03 Jul 2008 15:50:06 -0400

Dear Spencer,

In addition to the approaches already suggested, there is the recode() function in the car package.

Regards,
  John



John Fox, Professor
Department of Sociology
McMaster University
Hamilton ON Canada L8S 4M4
web: socserv.mcmaster.ca/jfox

On 3-Jul-08, at 2:57 PM, Spencer wrote:

> Hi All,
>
> I'm relatively new to R. I have a variable, "internet use," which
> ranges from "Almost everyday, "Several times a week," "Several times
> a month," "Seldom," "Never," and "Don't know." I want to recode
> this data into a new variable, say "use.internet," such that I have
> a dichotomous variable indicating simply whether or not they have
> access to the internet. Hence, I want to make "Never" and "Don't
> know" equal to 0, everything else 1. I thought about doing an
> if...then statement, but am not sure how to do this in R. This is
> easy to do in SPSS.
>
> A sample of the existing array is the following:
>
> Seldom Several times a week
> Several times a month
> Never
> Never Never Seldom
> Several times a week
> Never Never Almost everyday Never
> And the ideal new variable:
>
> 1
> 1
> 1
> 0
> 0
> 0
> 1
> 1
> 0
> 0
> 1
> 0
>
> Any help would be great!
>
> --
> Spencer Cohen
> PhD Student
> Department of Geography
> University of Washington
> Email: zhuge99_at_u.washington.edu
> Website: staff.washington.edu/zhuge99
>
> ______________________________________________
> 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. Received on Thu 03 Jul 2008 - 19:53:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jul 2008 - 21:32:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive