jeudi 2 avril 2015

IF/THEN/ELSE in R

everyone.


Hopefully an easy syntax question. I'm trying to create a new variable in a table in R which would say "1" if my patient was in the age range I was looking at, or "0" for no. The age range I'm interested is between 2-155. The code is running without any errors, but it is not working. When I look in my table, the new variable will say 1 even though the age4 is 158 Here is what I have:



table$newvar <- if (table$age4>=2 && table$age4 <=155) {table$newvar=1} else {age$ageapprop==0}


Any help is appreciated! Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire