Skip to content

Instantly share code, notes, and snippets.

@ZDaly
Created September 14, 2013 04:38
Show Gist options
  • Save ZDaly/6558864 to your computer and use it in GitHub Desktop.
Save ZDaly/6558864 to your computer and use it in GitHub Desktop.
Homework Number Two (Stat545a)
========================================================
In this assignment we will be taking a preliminary look at the **Gapminder** dataset. (Located [here](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt "Gapminder dataset on the course website") for those who are curious).
This will include:
* Loading the dataset
* Get a sense of the sort of information in the dataset
* Summarizing the variables in the dataset
* Creating a quick plot of some of the information in the dataset
We start by loading the dataset, as well as the needed libraries:
```{r}
gDat <- read.delim("gapminderDataFiveYear.txt")
library(lattice)
```
We now want to learn a little bit about the dataset that we are dealing with:
```{r}
str(gDat)
```
From the output we can see that there are 6 variables, with 1704 observations. I can also see what the variables are, and the manner in which they are coded.
Out of curiosity I want to take a peak at some of the actual data; once again, this is to get a better sense of what we are dealing with:
```{r}
tail(gDat)
```
Nothing too exciting to report so I decide to make a quick and dirty summary of the data:
```{r}
summary(gDat)
```
Amongst other things we can see that Oceania seems to be underrepresented in the dataset. Furthermore, the life expectency ranges from 23.6 to 82.6, and the dataset has data running from 1952 up till 2007.
Finally, I decide I want to make a plot. Given that my field work takes me to Zambia, I am curious to see what this dataset has to say about the country. I decide to make a plot of life expectency over the years in the country.
```{r fig.width=5, fig.height=5}
xyplot(lifeExp ~ year, gDat, subset = country == "Zambia", type = c("p", "r"), xlab = "Year", ylab = "Life Expectency", ylim = c(1, 60), main = "Life Expectency in Zambia", col = "red")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment