---
title: "Week 3 Lecture 2"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(gapminder)
library(tidyverse)
```

### Tidy data

Data frames that comform to the principle of tidy data have one row per data point, and one column per variable. The data frame `gapminder` conforms to the principle of tidy data

```{r}
gapminder
```

Note that there is one data point (i.e., measurement) per row. Each column corresponds to a different quantity that's being measured. (We could countries etc.). Here is an example of data that is *not* tidy. (We are not discussing `spread` in detail right now)

```{r}
spread(gapminder %>% select(country, year, lifeExp), key=country, value = lifeExp)[, c(1:7)]
```

Here, the life expectancies are recorded in multiple columns, not just one; and there are multiple measurements per row. This is a more concise way of presenting the information, if all we need to do is present the life expectancies in different countries in different years. This format is called "wide" (as opposed to the "long" (tidy) format of the original `gapminder` data frame -- you can see why).


