Reputation: 1
I am working on an assignment and I am stuck. My purpose is the divide the data into quartiles labeled low, medium and high groups split by their specific conditions. Low relates all of the data in the set up to but not including the 40% quantile break value of the sales value. Medium is between the range cut-offs for low and high sales. High is above the 85 quantile breaks. I am struggling with peicing the code all together. This is what I have so far. #EV9(part)[
sales_cat <- cut(df_XX$sales, breaks = c(quantile(df_XX$sales, probs = seq(0,1,by = .40), na.rm = TRUE)),right = TRUE, ordered = TRUE)
(https://i.sstatic.net/owbOz.png)[enter image description here](https://i.sstatic.net/uGvFO.png)
I tried my code above and I was expecting a results that splits breaks my data up into three groupd - at the right before 40% of sales mark, data that was over 85% and the data inbetween the 40 and 85 marks
Upvotes: 0
Views: 122
Reputation: 11056
First provide some data:
set.seed(42)
sales <- sample.int(100, 25, replace=TRUE)
Now set the breaks and create the groups:
brks <- quantile(sales, probs=c(0, .4, .85, 1))
grps <- cut(sales, brks, include.lowest=TRUE, labels=c("Low", "Medium", "High"))
table(grps)
# grps
# Low Medium High
# 10 11 4
Upvotes: 0