I have this numeric vector:
vec <- 1:7
How can I transform it into 3 categories using these logical rules:
if(vec >=
I'd recommend cut and its labels variable
cut
labels
cut(vec, c(1, 3, 5, 8), include.lowest = TRUE, labels = paste0("category", 1:3)) # [1] category1 category1 category1 category2 category2 category3 category3 # Levels: category1 category2 category3