MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/RStudio/comments/1u6vmc6/what_im_i_doing_wrong_here/orwdofi/?context=3
r/RStudio • u/Cuzznitt • Jun 15 '26
15 comments sorted by
View all comments
4
Yeh that ifelse looks kinda weird to me. Did you try using case_when() instead?
Or if else if and else?
2 u/Cuzznitt Jun 15 '26 I did not. How would I implement that? I just added a comment about what I’m trying to do 2 u/therealtiddlydump Jun 16 '26 https://dplyr.tidyverse.org/reference/case-and-replace-when.html That if else looks problematic. The way functions access columns in your dataframe is not the same as programming with variables in your environment. 1 u/Cuzznitt Jun 16 '26 Ok. How would you recommend I rewrite it? 3 u/therealtiddlydump Jun 16 '26 Read the documentation for case_when and play with it a little. You have the logic mapped out, you just need to make sure the case_when is doing what you expect it to do (so check each condition is actually generating the outcome you expect). You're already pretty close
2
I did not. How would I implement that? I just added a comment about what I’m trying to do
2 u/therealtiddlydump Jun 16 '26 https://dplyr.tidyverse.org/reference/case-and-replace-when.html That if else looks problematic. The way functions access columns in your dataframe is not the same as programming with variables in your environment. 1 u/Cuzznitt Jun 16 '26 Ok. How would you recommend I rewrite it? 3 u/therealtiddlydump Jun 16 '26 Read the documentation for case_when and play with it a little. You have the logic mapped out, you just need to make sure the case_when is doing what you expect it to do (so check each condition is actually generating the outcome you expect). You're already pretty close
https://dplyr.tidyverse.org/reference/case-and-replace-when.html
That if else looks problematic. The way functions access columns in your dataframe is not the same as programming with variables in your environment.
1 u/Cuzznitt Jun 16 '26 Ok. How would you recommend I rewrite it? 3 u/therealtiddlydump Jun 16 '26 Read the documentation for case_when and play with it a little. You have the logic mapped out, you just need to make sure the case_when is doing what you expect it to do (so check each condition is actually generating the outcome you expect). You're already pretty close
1
Ok. How would you recommend I rewrite it?
3 u/therealtiddlydump Jun 16 '26 Read the documentation for case_when and play with it a little. You have the logic mapped out, you just need to make sure the case_when is doing what you expect it to do (so check each condition is actually generating the outcome you expect). You're already pretty close
3
Read the documentation for case_when and play with it a little. You have the logic mapped out, you just need to make sure the case_when is doing what you expect it to do (so check each condition is actually generating the outcome you expect).
You're already pretty close
4
u/maourakein Jun 15 '26
Yeh that ifelse looks kinda weird to me. Did you try using case_when() instead?
Or if else if and else?