dimanche 10 mai 2020

how to make new column with if and else condition

what should i do when i want to make new column with mutate but with if condition status on it.

example :

dt <- read.table(text="
name,gender,fat_%
adam,male,32
anya,female,27
gilang,male,24
andine,female,34
",sep=',',header=TRUE) 


## + > dt
##       name gender fat_.
##   1   adam   male    32
##   2   anya female    27
##   3 gilang   male    24
##   4 andine female    34

my question : what code i have to write if i want to make new column where gonna take 2 answer "yes" or "no". and my new column will be like this :

name gender fat_% obesity adam male 32 yes anya female 27 no gilang male 24 yes andine female 34 no

note : formula to find obesity is (if male & fat > 26 = yes ,if girl & fat >32 = yes) if (if male & fat < 26 = no ,if girl & fat <32 = no)

Aucun commentaire:

Enregistrer un commentaire