Skip to main content

A student needs help with their project in R and you are going to assist them! Answer their questions below. If you get stuck, you can view the answers here.

Required dataset: wbi_r.csv

  1. I need to use dplyr. How do I load it?
  2. How do I load my csv file into a data frame?
  3. How do I list the variables I have in my dataset?
  4. How do I list rows 20 through 30 for the first 5 columns?
  5. How do I get a subset that includes only data from the year 2010?
  6. How do I subset my 2010 data so that I only have two columns: countries and mobile phone subscriptions?
  7. How do I tell R that the blanks in that subset represent missing values?
  8. How do I remove countries with missing data from that subset?
  9. How do I order the countries in that subset by highest number of mobile phone subscriptions to lowest?
  10. Maybe China’s high mobile phone subscriptions are a result of their high population. How can I add the population information back in? HINT: I need to MERGE my old dataframe with my new dataframe.
  11. Now I want to get phone subscriptions per capita. How do I write a function to do that in base R?
  12. How do I apply the function?
  13. What’s a simpler way to apply the same function using dplyr?
  14. Let’s use the dplyr created dataframe. How do I sort by mobile phone subscriptions per capita, also using dplyr this time?
  15. I want to add another column to my dataframe that has 3 categories: “More phones than people”, “One phone per person”, and “Fewer phones than people”. How do I do that?
  16. Now I’m interested in life expectancy over time. Using dplyr on my original dataframe, how can I get the average universal life expectancy for both males and females by year?
  17. I have a hunch that we can predict internet users by urban population. How do I fit a linear model?

More Exercises