Community Conundrum 25: Feature Visualization is now live! Read More

R application & and | together

Level 1
R application & and | together
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.
0 Kudos
3 Replies
Dataiker
Dataiker
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
0 Kudos
Level 1
Author
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
0 Kudos
Dataiker
Dataiker
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.
0 Kudos
Labels (2)