This is creating troubles to me,I am using dplyr and I want to change the value of each Week(W1 to W3) based on the value of CP: if < CP then 0
CP W1 W2 W3 W4
<dbl> <dbl> <dbl> <dbl> <dbl>
1 50 0 60 0 0
4 10 0 0 0 0
5 50 20 20 21 50
6 10 5 0 0 21
8 10 0 31 0 0
The desired output should is the following:
CP W1 W2 W3 W4
<dbl> <dbl> <dbl> <dbl> <dbl>
1 50 0 60 0 0
4 10 0 0 0 0
5 50 0 0 0 50
6 10 0 0 0 21
8 10 0 31 0 0
Do you have any idea on how to handle this problem with dplyr or other? Thank you!
mutate
andif_else
orcase_when
(I think). You can reshape to long too first. – NelsonGon