I am trying to change a value for a variable depending on other variables. So if value of one variable equals that of second variable then value of third variable should be multiplied by -1.
My code looks like this:
df <- df %>%
mutate (C = case_when((A1) == (A2) & (R1) == (R2) ~ C,
(A1) == (R1) & (A2) == (R2) ~ (-1L)*C))
where A1, A2, R1, R2 are character variables and C is a numerical variable.
I get
error: case_when(...)`.
must be a double vector, not a logical vector.
If I change (-1L) to (-1) then it gives me NA for C
TIA!!