Implement case_when in Queryverse

Can we implement case_when in Julia?
I am trying to achieve this R code using Queryverse in Julia

Example in R:
mutate(TIME = case_when(TIME == 0 ~ 95.9,
TIME == 0.08 ~ 96.08,
TIME == 0.25 ~ 96.25,
TIME == 0.50 ~ 96.5,
TIME == 1 ~ 97.0,
TIME == 3 ~ 99.0,
TIME == 8 ~ 104.0))
Any suggestions please? Thanks.

Match.jl should do what you want

1 Like

Thanks. I was not successful implementing this! any pointers towards an example would be helpful.

Share with us the code that you used to try and get it to work and we can give you pointers

I am trying to achieve TIME_2 column.
image

tried this dv.TIME = match(:TIME==0, 95.9) to selectively change 0 to 95.9 and get this error
image

Thanks.

Please see PSA: Make it easier to help you. It would be great if you could make a MWE.

Even without Match.jl, this is probably the syntax you are looking for:

df.TIME = map(df.TIME) do t 
t == 0 ? 95.9 :
t == 0.08 ? 96.08 :
t == 0.25 ? 96.25 :
t == 0.50 ? 96.5 :  
t == 1 ? 97.0 :
t == 3 ? 99.0 :
t == 8 ? 104.0 : missing
end
2 Likes

Great - this works. Thanks.

One final thing. Better to use missing instead of nothing at the end of the block. I put nothing by mistake and have edited my code.

missing is what is used for missing values for data applications, and nothing is used in a different way.

1 Like

great - thanks.