-1

enter image description here

Is that possible to list out all the countries of one continent to this type of data. If yes, please help me out.

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
Asha
  • 83
  • 1
  • 6
  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Jul 10 '18 at 06:28

1 Answers1

1

You could try countrycode package

library(dplyr)
library(countrycode)

df %>%
  #add a column having corresponding continent name in 'Continent' column
  mutate(Continent = countrycode(Country, 'country.name', 'continent')) %>%   
  group_by(Continent) %>%
  #aggregation based on Continent 
  summarise(Random_col_Mean = mean(Random_col))

which gives

  Continent Random_col_Mean
1 Americas              500
2 Asia                  600
3 Europe                222


Sample data: (In absence of reproducible example I have considered below data for the demonstration purpose)

df <- structure(list(Country = structure(c(3L, 3L, 1L, 6L, 2L, 5L, 
4L), .Label = c("Belgium", "Croatia", "France", "Japan", "Mexico", 
"UK"), class = "factor"), Random_col = c(100, 111, 200, 300, 
400, 500, 600)), .Names = c("Country", "Random_col"), row.names = c(NA, 
-7L), class = "data.frame")

  Country Random_col
1  France        100
2  France        111
3 Belgium        200
4      UK        300
5 Croatia        400
6  Mexico        500
7   Japan        600
1.618
  • 11,271
  • 1
  • 15
  • 32
  • You may want to [accept the answer](https://stackoverflow.com/help/someone-answers) if it helped you solve your problem so that the question can be considered close. – 1.618 Jul 11 '18 at 05:17