[R] r syntax

John Kane jrkrideau at inbox.com
Sun Apr 28 14:48:13 CEST 2013


Note that Rui used 1L and 2L to give you integers. If he had used 
1 and 2 you would have gotten real numbers.  

John Kane
Kingston ON Canada


> -----Original Message-----
> From: ruipbarradas at sapo.pt
> Sent: Sat, 27 Apr 2013 23:57:30 +0100
> To: infweb at gmail.com
> Subject: Re: [R] r syntax
> 
> Hello,
> 
> You should provide us with a data example.
> 
> In the following, the two solutions are completely different but both of
> them do what you want. Note that the second creates a factor variable,
> whose levels are coded as integers. See R-intro.pdf in your doc
> directory, chapter 4 Ordered and unordered factors.
> 
> 
> x <- sample(c("Male", "Female"), 10, replace = TRUE)
> 
> y1 <- ifelse(x == "Male", 1L, 2L)
> y2 <- factor(x, levels = c("Male", "Female"))
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 27-04-2013 15:32, sgs sys escreveu:
>> Hi
>> 
>> i  want  to recode Male  =1  and  female  =2  in  R
>> what  is  the  syntax  for  same ?
>> thanks
>> Sameer
>> 
>> 	[[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> 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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!



More information about the R-help mailing list