I am hoping someone could help please? I am currently doing a course in R and am having trouble with the below exercise. I am brand new to R so know this will be very simple for the majority of you!
I have pasted below what I have typed in in **, but I must be missing something and/or have something wrong, as whenever I go to click to open the spreadsheet, it just looks exactly the same? Can you advise where I am going wrong please?
To access this package, simply install and load gapminder . You can install gapminder, either by clicking on the Packages tab and navigating to the Install shortcut, or by running install.packages("gapminder") in the console. – managed to do this
As usual, we'll also need the tidyverse:
library(gapminder) – managed to do this
library(tidyverse) – managed to do this
Can you create an ordered subset of the gapminder data for the year 2007?-
First:
• create a new object called gap_2007
• gap_2007 <- gapminder, typed into the script window
Then combine two functions from dplyr to:
• filter() the gapminder data to extract only observations from the year 2007 gap_2007 %>%
** filter(year == 2007) %>%**
• arrange() the data to sort it in descending order of life expectancy (lifeExp ). gap_2007 %>%
** arrange(desc == lifeExp) %>%**
In R any results you calculate are ephemeral if you dont assign them to a name that would allow you to refer to them later. The assignment operator <- is used for this.
library(tidyverse)
library(gapminder)
# • create a new object called gap_2007
# • gap_2007 <- gapminder, typed into the script window
gap_2007 <- gapminder
# Then combine two functions from dplyr to:
# • filter() the gapminder data to extract only observations from the year 2007
# gap_2007 %>%
# ** filter(year == 2007) %>%**
# • arrange() the data to sort it in descending order of life expectancy (lifeExp ).
# gap_2007 %>%
# ** arrange(desc == lifeExp) %>%**
gap_2007 %>%
filter(year == 2007) %>%
arrange(desc(lifeExp))
This way I can see the result in the output. However, I have not assigned the result to any variable.
For these reason if you type gap_2007 you will see that it does not only include 2007 and that the data is not sorted.
typing gap_2007 this is the result