[R] making an inicator variable

2005-10-25 Thread Jennifer Dillon
Hello,

I am almost a total novice, and I am sure there must be an easy (and 
basic) way to turn a variable of 1's and 2's into a variable of zeros 
and ones.  This is in a data frame, but if I could do it with vectors, 
that's all I need.

Can someone tell me how?

Thanks so much,

Jen

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] making an inicator variable

2005-10-25 Thread Vincent Goulet
Le 25 Octobre 2005 15:51, Jennifer Dillon a écrit :
 Hello,

 I am almost a total novice, and I am sure there must be an easy (and
 basic) way to turn a variable of 1's and 2's into a variable of zeros
 and ones.  This is in a data frame, but if I could do it with vectors,
 that's all I need.

 Can someone tell me how?

 Thanks so much,

 Jen

What about

 x - 1

(where 'x' is a vector of 1's and 2's)?

-- 
  Vincent Goulet, Professeur agrégé
  École d'actuariat
  Université Laval, Québec 
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] making an inicator variable

2005-10-25 Thread Wensui Liu
x-c(1, 2);
y-ifelse(x==1, 1, 0);

On 10/25/05, Jennifer Dillon [EMAIL PROTECTED] wrote:

 Hello,

 I am almost a total novice, and I am sure there must be an easy (and
 basic) way to turn a variable of 1's and 2's into a variable of zeros
 and ones. This is in a data frame, but if I could do it with vectors,
 that's all I need.

 Can someone tell me how?

 Thanks so much,

 Jen

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html




--
WenSui Liu
(http://statcompute.blogspot.com)
Senior Decision Support Analyst
Cincinnati Children Hospital Medical Center

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] making an inicator variable

2005-10-25 Thread John Fox
Dear Jen,

There are lots of different ways to do what you want -- you've already had
two suggestions -- but you might consider whether you really need to do it.
In particular, R will generate its own indicator variables (and other kinds
of contrasts) in linear and other statistical models (see Section 11 of the
Introduction to R manual that comes with R). It's hard to give really good
advice without knowing more about the context.

I hope this helps,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Jennifer Dillon
 Sent: Tuesday, October 25, 2005 2:52 PM
 To: r-help@stat.math.ethz.ch
 Subject: [R] making an inicator variable
 
 Hello,
 
 I am almost a total novice, and I am sure there must be an easy (and
 basic) way to turn a variable of 1's and 2's into a variable 
 of zeros and ones.  This is in a data frame, but if I could 
 do it with vectors, that's all I need.
 
 Can someone tell me how?
 
 Thanks so much,
 
 Jen
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html