Home > Net >  Ranking the countries with the most records of a certain type
Ranking the countries with the most records of a certain type

Time:09-03

I am looking at different species of Melaleuca (bottlebrushes) that occur in different countries and have different invasion statuses.

I have a csv file called "Glonaffinal2" that looks like this: R script

But there are over 500 000 records.

I need to rank the countries (with the number); from the country with the most number of records, to the least number of records, for each invasive status (introduced, naturalized, invasive) separately.

Please can you help

CodePudding user response:

Maybe something like this solves the question's problem. Untested, since there are no data.

library(dplyr)

Glonaffinal2 %>%
  count(country, status) %>%
  mutate(rank = rank(-n)) %>%
  arrange(desc(rank), country)

CodePudding user response:

Well I'm no expert but I think you can do this easily with a sorting function. You can use MS Excel or Python. You just have to export the data to either an Excel sheet/Google sheets or python and use the sorting function there.

  •  Tags:  
  • r
  • Related