After performing a survey on perceived problems per neighborhood I get this dataframe. Since the survey had different options to choose from + an open one, the results on the open question are frequently irrelevant (see below):
library(dplyr)
library(splitstackshape)
df = read.csv("http://pastebin.com/raw.php?i=tQKHWMvL")
# Splitting multiple answers into different rows.
df = cSplit(df, "Problems", ",", direction = "long")
df = df %>%
group_by(Problems) %>%
summarise(Total = n()) %>%
mutate(freq = Total/sum(Total)*100) %>%
arrange(rank = desc(rank(freq)))
Resulting in this data frame:
> df
Source: local data table [34 x 3]
Problems Total freq
1 Hurtos o robos sin violencia 245 25.6008359
2 Drogas 232 24.2424242
3 Peleas callejeras 162 16.9278997
4 Ningún problema 149 15.5694880
5 Agresiones 66 6.8965517
6 Robos con violencia 62 6.4785789
7 Quema contenedores 6 0.6269592
8 Ruidos 5 0.5224660
9 NS/NC 4 0.4179728
10 Desempleo 2 0.2089864
.. ... ... ...
>
As you can see results after row 9 are mostly irrelevant (only one or two respondants per option), so I'd like them to be grouped into a single option (such as "others") without losing their relation to the neighborhood (that's why I cant rename the values now). Any suggestions?