I am trying to create a plot with the frequency of a factor. But I have 70 different factors. That is why I would like to create an 'other' group for everything that is not Top10.
It is currently working with the top_n()
function to create the top 10.
ProblemFrequency <- count(Disruptions, 'Problem')
Top10 <- top_n(ProblemFrequency, n=10, freq)
And I already got 'other' grouping to work by using within()
in combination with an if-else statement
ProblemFrequency <- within(ProblemFrequency, other.group <- ifelse(freq > 100, as.character(Problem), "Other"))
ProblemFrequency <- within(ProblemFrequency, relevel(factor(other.group), "Other"))
I have these two pieces working separately but I can't seem to figure out how to combine them. I am working with a shiny app where users can filter, the Top10 and their frequency is constantly changing, so I can't just use an equation.
I think the if statement should check if the factor is in the Top10. If not: group it into other.