I have this numeric vector:
vec <- 1:7
How can I transform it into 3 categories using these logical rules:
if(vec >= 1 && vec < 4) then "category1"
else if(vec >=4 && vec < 6) then "category2"
else if(vec >= 6 && vec < 8) then "category3"
The expected result would be:
result <- c("category1","category1","category1",
"category2","category2",
"category3","category3")
UPDATE:
What if category names are not sequential (i.e. cat1,cat2,cat3)? e.g.
if(vec >= 1 && vec < 4) then "night"
else if(vec >=4 && vec < 6) then "early morning"
else if(vec >= 6 && vec < 8) then "morning"
I'd recommend
cut
and itslabels
variable