I am attempting to create an additional column in my dataset that bucketizes percentiles. Ideally I would to create logic as follows:
CASE
WHEN percentile >= 75 AND percentile < 90 THEN "75%-89% Percentile"
WHEN percentile >= 50 AND percentile < 75 THEN "50%-75% Percentile"
END
What I have attempted dplyr is the following:
mutate(Bucket = case_when(as.double(percentile) >= 90 ~ "90%-100% Percentile",
as.double(percentile) >= 75 & as.double(percentile) < 90 ~ "75%-89% Percentile",
as.double(percentile) < 75 & as.double(percentile) >= 50 ~ "50%-75% Percentile",
as.double(percentile) < 50 & as.double(percentile) >= 25 ~ "25%-50% Percentile",
as.double(percentile) < 25 & as.double(percentile) >= 0 ~ "0%-25% Percentile"))
However it is not bucketizing correctly, see a sample of the results in the screenshot. The bucket flag for these percentiles should be "75%-89% Percentile" :