Create a variable using equations

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Create a variable using equations

mb3david
Hi everybody,

I have to create a variable using certain equation depending on the values of two variables (sex and age).

I have the following variables: sex, age, age2 and height2.

I have to generate fev1nh:

 if (datos$sex=="Women" & datos$age<18) {
    datos$fev1nh<-(-0.9641+0.06490*datos$age+0.00012154*datos$height2)
  } else if (datos$sex=="Women" & datos$age>=18) {
    datos$fev1nh<-(-0.4529-0.01178*datos$age-0.000113*datos$age2+0.00012154*datos$height2)
  } else if (datos$sex=="Men"   & datos$age<20){
    datos$fev1nh<-(-0.8218-0.04248*datos$age-0.004291*datos$age2+0.00015104*datos$height2)
  } else if (datos$sex=="Men"   & datos$age>=20) {
    datos$fev1nh<-(0.6306-0.02928*datos$age+0.00015104*datos$height2)
  } else 0

The warning message was:

Warning messages:
1: In if (datos$sex == "Women" & datos$age < 18) { :
  the condition has length > 1 and only the first element will be used
2: In if (datos$sex == "Women" & datos$age >= 18) { :
  the condition has length > 1 and only the first element will be used´╗┐

Even though some values are genetared, these values are wrong.

Could you help me?

Thanks,
David