Skip to content
Prev 77134 / 398502 Next

if() command

Hallo
On 13 Sep 2005 at 10:29, Carlos Maur??cio Cardeal Mende wrote:

            
from
if you put your statement on one line it works (at least it does not  
give you syntax error) but the result is hardly what you really  
expect 

age<-sample(seq(10,50,10), 20, replace=T) 

if (age <=10) {group <- 1} else if (age > 10 & age <= 20) {group 
<- 2} else {group <- 3} 
if (age <=10) {group == 1} else if (age > 10 & age <= 20) {group 
== 2} else {group == 3} 

Maybe you want something like 

group<-as.numeric(cut(age,c(0,10,20,100))) 

but it is only guess 

HTH 
Petr
even
Petr Pikal
petr.pikal at precheza.cz