Exercise

Rule the world: part II

Remember that in the previous challenge you created your own data frame, countries_df? Well, in this challenge you will get to play around with this data frame some more! Suppose you are no longer interested in the economic variables gdp and hdi. Instead you want to learn more about the demography of the countries. Also, since you are planning a trip to Brazil this summer, you want to include some information on this country to your data frame. Finally, you want to keep the overview and have the countries with the largest population appear first in your data frame. Sounds like an easy job after completing the previous set of exercises, right?

Instructions

200xp

Subset countries_df to drop the columns gdp and hdi. You can use single brackets for this. Next, add the variable population to your dataframe. Again, there are several ways to do this; one way is to use the cbind() function. Store the resulting data frame again countries_df_dem.

Include the data on your future holiday destination: Brazil. This comes down to adding a new observation, so you have to make sure that the names of brazil match those in countries_df_dem. Next you can use the rbind() function to merge the dataframes into the new dataframe countries_df2.

All that is left to do is sort the observations according to population size. Note that you want the largest population to be represented first. Therefore, you'll need order() with the decreasing argument equal to TRUE. Just print it, do not overwrite the countries_df2 dataframe.