Home > Software engineering >  is there a way to group outliers by factor and segment
is there a way to group outliers by factor and segment

Time:12-17

I am trying to get the outlier grouped by factor and segment

df %>%
group_by(factor,segment) %>%
summarise(boxplot= list( boxplot.stats(column_name)$out),
out = list( c('out') ) ) %>%
unnest(stat, boxplot) %>%
spread(stat, boxplot)

Error in eval(substitute(expr), envir, enclos) : invalid subscript type 'double'

CodePudding user response:

If you're trying to see the outliers, outliers are identified as those points that fall 1.5*IQR past the first or third quartile. You could define this quantity and then filter. This is what it would look like in the diamonds data, grouping outliers on price by cut and color:

out_diamonds <- diamonds %>% 
  group_by(cut, color) %>% 
  mutate(hinge_spread = 1.5*IQR(price), 
         lwr = quantile(price, .25) - hinge_spread, 
         upr = quantile(price, .75)   hinge_spread) %>%
  filter(price > upr | price < lwr)

CodePudding user response:

Perfect thanks alot I have been trying to solve it for week this seems to work

  •  Tags:  
  • r
  • Related