Convert variables to 1 and 0


I have a dependent variable which has values of 1 and 2. How can i convert it to 0 and 1?

I have another query w.r.t to the independent variables i.e.
Q: While running a logistic regression, is is mandatory to convert all the independent variables into dummies? Sa for eg: I have a variables X which has values ranging from 1 to 10. Do i need to create dummies for this variable X before running the regression?


Not trying to be facetious, but have you considered subtracting 1?

Could you please try to use a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ, linked to below.

You should ask this in another topic in Machine Learning and Modeling channel i think.

1 Like

Logistic regressions may accept continuous, discrete, dichotomous, or a mix of any of these as explanatory variables.

I personally like the UCLA Institute for Digital Research and Education R resource pages, which has a handy guide to applying logit-model in R. LOGIT REGRESSION | R DATA ANALYSIS EXAMPLES.