I want to create a new column in my data frame, and based on the previous column. I want to set conditions where when the value in the column equals 0, return 100. If the value equals 70, it returns 0. Every other value in that column returns something between 0 and 100 based on the above conditions.
For example: 0m = 100, 70m = 100, 35m = 50
How can I do this using the following example data?
df <- vars = c(28.9031759, 13.4701022, 66.3066303, 71.1803383, 21.4627313, 68.1418523, 65.3003990, 52.0964668))
df %>% mutate(conditional_vars = ifelse(vars == 0, 100, ifelse(vars == 70, 0, 0:100)))
I try using this code however it returns the continuous count from 0 to 100 without the condition that 0 = 100 and 70 = 0, like below:
| vars | conditional vars |
|---|---|
| 28.9 | 0 |
| 13.5 | 1 |
| 66.3 | 2 |
| 71.2 | 3 |
| 21.5 | 4 |
| 68.1 | 5 |
How can I fix this so it meets my continuous conditions?