R application & and | together

Options
AnastasiiaSolom
AnastasiiaSolom Registered Posts: 13 ✭✭✭✭
Good aftrenoon,

I am currently programming in R through the Dataiku and I have a very special question, how can I write this two logical characters in the same phrase? When I am working just with & or | separetly it is working, but once I try:

direction_final=
ifelse(directeur=="MINISTRE"|directeur=="PREFET"|(directeur=="MAIRE"&publique!=""),"Direction Général",""
)

So my question is it possible to use & and | together n the same part of the ifelse? And if it possible how can I get a good answer?

Thank you in advance for your answer.
Tagged:

Answers

  • Joachim_Zentici
    Joachim_Zentici Dataiker, Alpha Tester Posts: 8 Dataiker
    Options
    Hello,


    R has two operators for 'and' and 'or', single or double: & / && and | / ||

    You can google the precise difference between them but in your case you should use the double forms.

    Regards,
    Joachim
    R&D engineer
  • AnastasiiaSolom
    AnastasiiaSolom Registered Posts: 13 ✭✭✭✭
    Options
    Thank you fo the answer, but actually I can not, as "directeur" and so son it is a vector, and I want to apply "ifelse" for each row.

    Thank you
  • Joachim_Zentici
    Joachim_Zentici Dataiker, Alpha Tester Posts: 8 Dataiker
    Options
    Hum, this is definitely an R question and not DSS related but it looks indeed like a correct R syntax. I don't know what problem you are actually experiencing (in particular, error or output you don't expect) but I can tell you that you can indeed combine those boolean operators. If you find it easier to separate the computation into several steps that you can check individually, don't hesitate.
Setup Info
    Tags
      Help me…