0

I want to group the following:

Sample Data:

ProductId           Category    Price
-------------------------------------
628D5D44D6C7B525    accessories 0

6B079EE7E6794C05    accessories 0

2D5F744CBC63BF37    accessories 0

1A410674D1FD44D5    accessories 0

25807921234D4A73    jewellery   18923

27458D0C361B0B7     jewellery   18995

7F1152404511B7F5    jewellery   19021

acse<-
  select(prcbrkt, ProductId:Price) %>%
  group_by(Category) %>%
  mutate(price_Level <- 
              cut(Price, breaks = quantile(Price, c(0, .25, .50, .75)),
              labels = c('Low', 'Medium', 'High'),
              include.lowest = TRUE))

This leads to the following Error-Message:

Error in mutate_impl(.data, dots) : Evaluation error: 'probs' outside [0,1].

I am trying to write an algo where it has to display as which price bracket(High, Med or Low) will that productID falls in

for example: When I enter a productID it should display as below:

78BF0560126D416F    jewellery   18472 HIGH
Nick
  • 1,178
  • 3
  • 24
  • 36
  • Obviously you can't have `Inf` as a probability in `quantile`. See `?quantile`. – Maurits Evers Feb 07 '18 at 10:33
  • Please, help us help you by providing a minimal reproducible example as described here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Georgery Feb 07 '18 at 12:09
  • @MauritsEvers: If I remove Inf I am getting the below error Error in mutate_impl(.data, dots) : Evaluation error: 'breaks' are not unique – Abhishek BS Feb 08 '18 at 05:55
  • @AbhishekBS It's pretty much impossible to help without you providing a minimal reprex including sample data. This seems to be an issue related to how you use `cut`. `?cut` may provide some insight. – Maurits Evers Feb 08 '18 at 12:07
  • @MauritsEvers: I have added sample data. – Abhishek BS Feb 08 '18 at 15:05
  • Please *read* the link in Georgery's comment; then provide sample data in an appropriate format (preferablly `dput(...)` or `dput(head(...))`). That aside, I think there is a bigger issue/misunderstanding at hand. Take a look at the quantiles for a vector `c(0, 0, 0, 0)` (as is the case for `Category = accessories`). How do you expect `cut` to work in that case? As I said before, I recommend spending some time reading up on `?cut`. I think you might not've fully understood how `cut` works. Better to do some research, edit your question, and clearly state your expected outcome (still missing). – Maurits Evers Feb 08 '18 at 21:31

0 Answers0