Skip to content
Prev 77126 / 398502 Next

if() command

Carlos Maur??cio Cardeal Mendes wrote:
Because the following line is syntatically correct:

if (age <=10) {group == 1}

the R parser does not expect the following:

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

causing a sytax error. Instead, you want:

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

HTH,

--sundar