siuba icon indicating copy to clipboard operation
siuba copied to clipboard

if else statement in mutate function

Open TonyFly3000 opened this issue 3 years ago • 1 comments

Hi Michael,

Could we use if else statement in mutate function? I found this part is empty in the document.

https://siuba.readthedocs.io/en/latest/api_table_core/05_mutate.html#With-if_else-and-case_when

Thanks

TonyFly3000 avatar Jul 28 '21 04:07 TonyFly3000

You can!

from siuba import *
from siuba.data import mtcars

(
    mtcars
    >> mutate(hp_category = if_else(_.hp >= 150, "high hp", "low hp"))
)

essicolo avatar Aug 02 '21 17:08 essicolo

I've added a page in the siuba guide showing if_else used outside and inside of verbs :)

https://siuba.org/guide/ops-case-when.html

machow avatar Nov 16 '22 18:11 machow