lundi 23 juillet 2018

R case insensitive if check

What is the best way to create a case insensitive if statement?

For example if I have var = 'ignore'

if(var == 'Ignore'){print("pass")} else{print("fail")}

Will fail.

Some options that will pass include:

if(var == 'Ignore' | var == 'ignore' ){print("pass")} else{print("fail")}

if(tolower(var) == tolower('Ignore') ){print("pass")} else{print("fail")}

if(toupper(var) == toupper('Ignore') ){print("pass")} else{print("fail")}

Are there any other good options? Is there a best option(s)?

I'm not sure how "best" should be measured

Aucun commentaire:

Enregistrer un commentaire