mardi 26 juin 2018

Three logical operators in R

I would like to check three logical operators in R in the same line. That is I want Y1 to become 1 if x1 or x3 are smaller than 0.05 or x2 is smaller than 0.1

if (x1 <0.05 | x2 < 0.1 | x3 <0.05) {  
    Y1 <- 1 
  } 

However, R gives me the following error message:

## Warning in if (x1 < 0.05 | x2 < 0.1 | x3 < 0.05) {: the condition has length > 1 and only the first element will be used

Why does R give me an error message? And if it is a problem how can I solve this without using two if-statements?

Aucun commentaire:

Enregistrer un commentaire