Hello I have a variable and based on it I wanted to generate another variable when the first one is between certain values. I am trying with this code, but it gives me error. I want to create values from 0 to 4 to "category" the new variable.
library(tidyverse)
my_data <- tibble(Var_1 = c(1, 5, 8, 90, 1500, 350, 1200, 450,125,250,300)
my_data %>%
mutate(category = case_when(
Var_1 < 50 ~ 0,
Var_1<= 99 & Var_1>= 50 ~ 1,
Var_1<= 199 & Var_1>= 100 ~ 2,
Var_1<= 499 & Var_1>= 200 ~ 3,
Var_1<= 500 ~ 4,
TRUE ~ Var_1))```