-4

I want to show sum of cluster in different districts on a map in R. The data file i have imported in R studio contains total of 11 clusters appearing multiple times in a district. Below is the data example:

District       cluster
Rawalpindi     A
Lahore         A
Multan         A
Rawalpindi     A
Rawalpindi     A
Lahore         A
Lahore         A
Lahore         A
Multan         A
Rawalpindi     B
Rawalpindi     B
Rawalpindi     B
Rawalpindi     A
Lahore         B
Lahore         B
Multan         B
Multan         B
Rawalpindi     C
Rawalpindi     C
Rawalpindi     C
Rawalpindi     C
Rawalpindi     C
Rawalpindi     C
Lahore         C

I want to crate a separate file to work with to create map, which will contain only the sum of clusters according to districts. Your help will be highly appreciated

mnm
  • 1,962
  • 4
  • 19
  • 46
Nido
  • 55
  • 1
  • 1
  • 10
  • 1
    do take a look at this [post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and learn how to create a reproducible example. You need to show what have you tried so far and where are you stuck at. StackOverflow is NOT a code-vending website. – mnm Jun 04 '18 at 08:20
  • 1
    What have you tried so far? – J. Win. Jun 04 '18 at 08:41
  • i have downloaded the map in R and now want to show my data i.e number of cluster in a district as a circle. The size of the circle will show the number/times that cluster appeared in specific district – Nido Jun 04 '18 at 08:45

1 Answers1

1
#Sample dataframe 
df <- data.frame(District=c('Rawalpindi','Lahore','Multan', 'Rawalpindi', 'Lahore'), cluster=c('A', 'A', 'A', 'B', 'B'))
fun <- function(col){ length(unique(col)) }
aggregate(cluster ~ District, df, fun)
Aniket Rangrej
  • 192
  • 1
  • 7