I am looking to create a new variable that indicates if an individual is to the left or right side (if their 'y' value is greater than 'a' they're to the left, if their y value is less than a they are to the right). I have tried this code:
df <- df %>%
mutate(Side = case_when(y > a ~ "Left",
y < a ~ "Right",
y = a ~ "C"))
However, when I try it I get this error:
Error: Problem with `mutate()` input `Side`.
x object 'y' not found
ℹ Input `Side` is `case_when(y > a ~ "Left", y < a ~ "Right", y = a ~ "C")`.
I am very lost since both a and y are numeric vectors. Any idea why this is?
structure(list(y = c(26.85, 26.85, 26.85, 26.85, 26.85,
26.85, 26.85, 26.85, 26.85, 26.85, 26.85, 26.85, 26.85, 26.85,
26.85, 26.85, 26.85, 26.85, 26.85, 26.85), a = c(26.67, 36.47,
44.16, 22.01, 36.15, 28.7, 26.63, 31.12, 20.53, 43.49, 21.83,
26.59, 26.71, 26.85, 26.67, 36.47, 44.17, 22, 36.15, 28.7)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
``