HTP
November 16, 2022, 10:11pm
1
Suppose that I have this chunk of code below that gives me some numerical results. How can I change this so that it will remove negative results (i.e., remove anything that's below zero)? That is, I only want results that are 0 or above.
Final_df <- Initial_df %>%
mutate(Result= case_when(
`Type` == "A" ~ (Capability - Output)*(sum(Capability) - sum(Output)),
`Type` == "B" | `Type` == "C" ~ (Forecast - Output),
`Type` == "D" ~ Capability - Output))
Thank you,
FJCC
November 16, 2022, 10:20pm
2
If you want to remove rows where Result is less than zero, I suggest you add a filter step.
Final_df <- Initial_df %>%
mutate(Result= case_when(
`Type` == "A" ~ (Capability - Output)*(sum(Capability) - sum(Output)),
`Type` == "B" | `Type` == "C" ~ (Forecast - Output),
`Type` == "D" ~ Capability - Output)) %>%
filter(Result >= 0)
1 Like
system
Closed
November 23, 2022, 10:21pm
3
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.