diff --git a/01-rstudio-intro.md b/01-rstudio-intro.md new file mode 100644 index 000000000..a144f0e60 --- /dev/null +++ b/01-rstudio-intro.md @@ -0,0 +1,893 @@ +--- +title: Introduction to R and RStudio +teaching: 45 +exercises: 10 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Describe the purpose and use of each pane in RStudio +- Locate buttons and options in RStudio +- Define a variable +- Assign data to a variable +- Manage a workspace in an interactive R session +- Use mathematical and comparison operators +- Call functions +- Manage packages + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How to find your way around RStudio? +- How to interact with R? +- How to manage your environment? +- How to install packages? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +## Before Starting The Workshop + +Please ensure you have the latest version of R and RStudio installed on your machine. This is important, as some packages used in the workshop may not install correctly (or at all) if R is not up to date. + +- [Download and install the latest version of R here](https://www.r-project.org/) +- [Download and install RStudio here](https://www.rstudio.com/products/rstudio/download/#download) + + +## Why use R and R studio? + +Welcome to the R portion of the Software Carpentry workshop! + +Science is a multi-step process: once you've designed an experiment and collected +data, the real fun begins with analysis! Throughout this lesson, we're going to teach you some of the fundamentals of the R language as well as some best practices for organizing code for scientific projects that will make your life easier. + +Although we could use a spreadsheet in Microsoft Excel or Google sheets to analyze our data, these tools are limited in their flexibility and accessibility. Critically, they also are difficult to share steps which explore and change the raw data, which is key to ["reproducible" research](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1003285). + +Therefore, this lesson will teach you how to begin exploring your data using R and RStudio. The R program is available for Windows, Mac, and Linux operating systems, and is a freely-available where you downloaded it above. To run R, all you need is the R program. + +However, to make using R easier, we will use the program RStudio, which we also downloaded above. RStudio is a free, open-source, Integrated Development +Environment (IDE). It provides a built-in editor, works on all platforms (including +on servers) and provides many advantages such as integration with version +control and project management. + +## Overview + +We will begin with raw data, perform exploratory analyses, and learn how to plot results graphically. This example starts with a dataset from [gapminder.org](https://www.gapminder.org) containing population information for many +countries through time. Can you read the data into R? Can you plot the population for +Senegal? Can you calculate the average income for countries on the continent of Asia? +By the end of these lessons you will be able to do things like plot the populations +for all of these countries in under a minute! + + +**Basic layout** + +When you first open RStudio, you will be greeted by three panels: + +- The interactive R console/Terminal (entire left) +- Environment/History/Connections (tabbed in upper right) +- Files/Plots/Packages/Help/Viewer (tabbed in lower right) + +![](fig/01-rstudio.png){alt='RStudio layout'} + +Once you open files, such as R scripts, an editor panel will also open +in the top left. + +![](fig/01-rstudio-script.png){alt='RStudio layout with .R file open'} + +::::::::::::::::::::::::::::::::::::::::: callout + +## R scripts + +Any commands that you write in the R console can be saved to a file +to be re-run again. Files containing R code to be ran in this way are +called R scripts. R scripts have `.R` at the end of their names to +let you know what they are. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Workflow within RStudio + +There are two main ways one can work within RStudio: + +1. Test and play within the interactive R console then copy code into + a .R file to run later. + - This works well when doing small tests and initially starting off. + - It quickly becomes laborious +2. Start writing in a .R file and use RStudio's short cut keys for the Run command + to push the current line, selected lines or modified lines to the + interactive R console. + - This is a great way to start; all your code is saved for later + - You will be able to run the file you create from within RStudio + or using R's `source()` function. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Running segments of your code + +RStudio offers you great flexibility in running code from within the editor +window. There are buttons, menu choices, and keyboard shortcuts. To run the +current line, you can + +1. click on the `Run` button above the editor panel, or +2. select "Run Lines" from the "Code" menu, or +3. hit Ctrl\+Return in Windows or Linux + or \+Return on OS X. + (This shortcut can also be seen by hovering + the mouse over the button). To run a block of code, select it and then `Run`. + If you have modified a line of code within a block of code you have just run, + there is no need to reselect the section and `Run`, you can use the next button + along, `Re-run the previous region`. This will run the previous code block + including the modifications you have made. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Introduction to R + +Much of your time in R will be spent in the R interactive +console. This is where you will run all of your code, and can be a +useful environment to try out ideas before adding them to an R script +file. This console in RStudio is the same as the one you would get if +you typed in `R` in your command-line environment. + +The first thing you will see in the R interactive session is a bunch +of information, followed by a ">" and a blinking cursor. In many ways +this is similar to the shell environment you learned about during the +shell lessons: it operates on the same idea of a "Read, evaluate, +print loop": you type in commands, R tries to execute them, and then +returns a result. + +## Using R as a calculator + +The simplest thing you could do with R is to do arithmetic: + + +``` r +1 + 100 +``` + +``` output +[1] 101 +``` + +And R will print out the answer, with a preceding "[1]". [1] is the index of +the first element of the line being printed in the console. For more information +on indexing vectors, see [Episode 6: Subsetting Data](https://swcarpentry.github.io/r-novice-gapminder/06-data-subsetting/index.html). + +If you type in an incomplete command, R will wait for you to +complete it. If you are familiar with Unix Shell's bash, you may recognize this behavior from bash. + +```r +> 1 + +``` + +```output ++ +``` + +Any time you hit return and the R session shows a "+" instead of a ">", it +means it's waiting for you to complete the command. If you want to cancel +a command you can hit Esc and RStudio will give you back the ">" prompt. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Canceling commands + +If you're using R from the command line instead of from within RStudio, +you need to use Ctrl\+C instead of Esc +to cancel the command. This applies to Mac users as well! + +Canceling a command isn't only useful for killing incomplete commands: +you can also use it to tell R to stop running code (for example if it's +taking much longer than you expect), or to get rid of the code you're +currently writing. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +When using R as a calculator, the order of operations is the same as you +would have learned back in school. + +From highest to lowest precedence: + +- Parentheses: `(`, `)` +- Exponents: `^` or `**` +- Multiply: `*` +- Divide: `/` +- Add: `+` +- Subtract: `-` + + +``` r +3 + 5 * 2 +``` + +``` output +[1] 13 +``` + +Use parentheses to group operations in order to force the order of +evaluation if it differs from the default, or to make clear what you +intend. + + +``` r +(3 + 5) * 2 +``` + +``` output +[1] 16 +``` + +This can get unwieldy when not needed, but clarifies your intentions. +Remember that others may later read your code. + + +``` r +(3 + (5 * (2 ^ 2))) # hard to read +3 + 5 * 2 ^ 2 # clear, if you remember the rules +3 + 5 * (2 ^ 2) # if you forget some rules, this might help +``` + +The text after each line of code is called a +"comment". Anything that follows after the hash (or octothorpe) symbol +`#` is ignored by R when it executes code. + +Really small or large numbers get a scientific notation: + + +``` r +2/10000 +``` + +``` output +[1] 2e-04 +``` + +Which is shorthand for "multiplied by `10^XX`". So `2e-4` +is shorthand for `2 * 10^(-4)`. + +You can write numbers in scientific notation too: + + +``` r +5e3 # Note the lack of minus here +``` + +``` output +[1] 5000 +``` + +## Mathematical functions + +R has many built in mathematical functions. To call a function, +we can type its name, followed by open and closing parentheses. +Functions take arguments as inputs, anything we type inside the parentheses of a function is considered an argument. Depending on the function, the number of arguments can vary from none to multiple. For example: + + +``` r +getwd() #returns an absolute filepath +``` + +doesn't require an argument, whereas for the next set of mathematical functions we will need to supply the function a value in order to compute the result. + + +``` r +sin(1) # trigonometry functions +``` + +``` output +[1] 0.841471 +``` + + +``` r +log(1) # natural logarithm +``` + +``` output +[1] 0 +``` + + +``` r +log10(10) # base-10 logarithm +``` + +``` output +[1] 1 +``` + + +``` r +exp(0.5) # e^(1/2) +``` + +``` output +[1] 1.648721 +``` + +Don't worry about trying to remember every function in R. You +can look them up on Google, or if you can remember the +start of the function's name, use the tab completion in RStudio. + +This is one advantage that RStudio has over R on its own, it +has auto-completion abilities that allow you to more easily +look up functions, their arguments, and the values that they +take. + +Typing a `?` before the name of a command will open the help page +for that command. When using RStudio, this will open the 'Help' pane; +if using R in the terminal, the help page will open in your browser. +The help page will include a detailed description of the command and +how it works. Scrolling to the bottom of the help page will usually +show a collection of code examples which illustrate command usage. +We'll go through an example later. + +## Comparing things + +We can also do comparisons in R: + + +``` r +1 == 1 # equality (note two equals signs, read as "is equal to") +``` + +``` output +[1] TRUE +``` + + +``` r +1 != 2 # inequality (read as "is not equal to") +``` + +``` output +[1] TRUE +``` + + +``` r +1 < 2 # less than +``` + +``` output +[1] TRUE +``` + + +``` r +1 <= 1 # less than or equal to +``` + +``` output +[1] TRUE +``` + + +``` r +1 > 0 # greater than +``` + +``` output +[1] TRUE +``` + + +``` r +1 >= -9 # greater than or equal to +``` + +``` output +[1] TRUE +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Comparing Numbers + +A word of warning about comparing numbers: you should +never use `==` to compare two numbers unless they are +integers (a data type which can specifically represent +only whole numbers). + +Computers may only represent decimal numbers with a +certain degree of precision, so two numbers which look +the same when printed out by R, may actually have +different underlying representations and therefore be +different by a small margin of error (called Machine +numeric tolerance). + +Instead you should use the `all.equal` function. + +Further reading: [http://floating-point-gui.de/](https://floating-point-gui.de/) + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Variables and assignment + +We can store values in variables using the assignment operator `<-`, like this: + + +``` r +x <- 1/40 +``` + +Notice that assignment does not print a value. Instead, we stored it for later +in something called a **variable**. `x` now contains the **value** `0.025`: + + +``` r +x +``` + +``` output +[1] 0.025 +``` + +More precisely, the stored value is a *decimal approximation* of +this fraction called a [floating point number](https://en.wikipedia.org/wiki/Floating_point). + +Look for the `Environment` tab in the top right panel of RStudio, and you will see that `x` and its value +have appeared. Our variable `x` can be used in place of a number in any calculation that expects a number: + + +``` r +log(x) +``` + +``` output +[1] -3.688879 +``` + +Notice also that variables can be reassigned: + + +``` r +x <- 100 +``` + +`x` used to contain the value 0.025 and now it has the value 100. + +Assignment values can contain the variable being assigned to: + + +``` r +x <- x + 1 #notice how RStudio updates its description of x on the top right tab +y <- x * 2 +``` + +The right hand side of the assignment can be any valid R expression. +The right hand side is *fully evaluated* before the assignment occurs. + +Variable names can contain letters, numbers, underscores and periods but no spaces. They +must start with a letter or a period followed by a letter (they cannot start with a number nor an underscore). +Variables beginning with a period are hidden variables. +Different people use different conventions for long variable names, these include + +- periods.between.words +- underscores\_between\_words +- camelCaseToSeparateWords + +What you use is up to you, but **be consistent**. + +It is also possible to use the `=` operator for assignment: + + +``` r +x = 1/40 +``` + +But this is much less common among R users. The most important thing is to +**be consistent** with the operator you use. There are occasionally places +where it is less confusing to use `<-` than `=`, and it is the most common +symbol used in the community. So the recommendation is to use `<-`. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Which of the following are valid R variable names? + + +``` r +min_height +max.height +_age +.mass +MaxLength +min-length +2widths +celsius2kelvin +``` + +::::::::::::::: solution + +## Solution to challenge 1 + +The following can be used as R variables: + + +``` r +min_height +max.height +MaxLength +celsius2kelvin +``` + +The following creates a hidden variable: + + +``` r +.mass +``` + +The following will not be able to be used to create a variable + + +``` r +_age +min-length +2widths +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Vectorization + +One final thing to be aware of is that R is *vectorized*, meaning that +variables and functions can have vectors as values. In contrast to physics and +mathematics, a vector in R describes a set of values in a certain order of the +same data type. For example: + + +``` r +1:5 +``` + +``` output +[1] 1 2 3 4 5 +``` + +``` r +2^(1:5) +``` + +``` output +[1] 2 4 8 16 32 +``` + +``` r +x <- 1:5 +2^x +``` + +``` output +[1] 2 4 8 16 32 +``` + +This is incredibly powerful; we will discuss this further in an +upcoming lesson. + +## Managing your environment + +There are a few useful commands you can use to interact with the R session. + +`ls` will list all of the variables and functions stored in the global environment +(your working R session): + + +``` r +ls() +``` + + +``` output +[1] "x" "y" +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: hidden objects + +Like in the shell, `ls` will hide any variables or functions starting +with a "." by default. To list all objects, type `ls(all.names=TRUE)` +instead + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Note here that we didn't give any arguments to `ls`, but we still +needed to give the parentheses to tell R to call the function. + +If we type `ls` by itself, R prints a bunch of code instead of a listing of objects. + + +``` r +ls +``` + +``` output +function (name, pos = -1L, envir = as.environment(pos), all.names = FALSE, + pattern, sorted = TRUE) +{ + if (!missing(name)) { + pos <- tryCatch(name, error = function(e) e) + if (inherits(pos, "error")) { + name <- substitute(name) + if (!is.character(name)) + name <- deparse(name) + warning(gettextf("%s converted to character string", + sQuote(name)), domain = NA) + pos <- name + } + } + all.names <- .Internal(ls(envir, all.names, sorted)) + if (!missing(pattern)) { + if ((ll <- length(grep("[", pattern, fixed = TRUE))) && + ll != length(grep("]", pattern, fixed = TRUE))) { + if (pattern == "[") { + pattern <- "\\[" + warning("replaced regular expression pattern '[' by '\\\\['") + } + else if (length(grep("[^\\\\]\\[<-", pattern))) { + pattern <- sub("\\[<-", "\\\\\\[<-", pattern) + warning("replaced '[<-' by '\\\\[<-' in regular expression pattern") + } + } + grep(pattern, all.names, value = TRUE) + } + else all.names +} + + +``` + +What's going on here? + +Like everything in R, `ls` is the name of an object, and entering the name of +an object by itself prints the contents of the object. The object `x` that we +created earlier contains 1, 2, 3, 4, 5: + + +``` r +x +``` + +``` output +[1] 1 2 3 4 5 +``` + +The object `ls` contains the R code that makes the `ls` function work! We'll talk +more about how functions work and start writing our own later. + +You can use `rm` to delete objects you no longer need: + + +``` r +rm(x) +``` + +If you have lots of things in your environment and want to delete all of them, +you can pass the results of `ls` to the `rm` function: + + +``` r +rm(list = ls()) +``` + +In this case we've combined the two. Like the order of operations, anything +inside the innermost parentheses is evaluated first, and so on. + +In this case we've specified that the results of `ls` should be used for the +`list` argument in `rm`. When assigning values to arguments by name, you *must* +use the `=` operator!! + +If instead we use `<-`, there will be unintended side effects, or you may get an error message: + + +``` r +rm(list <- ls()) +``` + +``` error +Error in rm(list <- ls()): ... must contain names or character strings +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Warnings vs. Errors + +Pay attention when R does something unexpected! Errors, like above, +are thrown when R cannot proceed with a calculation. Warnings on the +other hand usually mean that the function has run, but it probably +hasn't worked as expected. + +In both cases, the message that R prints out usually give you clues +how to fix a problem. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## R Packages + +It is possible to add functions to R by writing a package, or by +obtaining a package written by someone else. As of this writing, there +are over 10,000 packages available on CRAN (the comprehensive R archive +network). R and RStudio have functionality for managing packages: + +- You can see what packages are installed by typing + `installed.packages()` +- You can install packages by typing `install.packages("packagename")`, + where `packagename` is the package name, in quotes. +- You can update installed packages by typing `update.packages()` +- You can remove a package with `remove.packages("packagename")` +- You can make a package available for use with `library(packagename)` + +Packages can also be viewed, loaded, and detached in the Packages tab of the lower right panel in RStudio. Clicking on this tab will display all of the installed packages with a checkbox next to them. If the box next to a package name is checked, the package is loaded and if it is empty, the package is not loaded. Click an empty box to load that package and click a checked box to detach that package. + +Packages can be installed and updated from the Package tab with the Install and Update buttons at the top of the tab. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +What will be the value of each variable after each +statement in the following program? + + +``` r +mass <- 47.5 +age <- 122 +mass <- mass * 2.3 +age <- age - 20 +``` + +::::::::::::::: solution + +## Solution to challenge 2 + + +``` r +mass <- 47.5 +``` + +This will give a value of 47.5 for the variable mass + + +``` r +age <- 122 +``` + +This will give a value of 122 for the variable age + + +``` r +mass <- mass * 2.3 +``` + +This will multiply the existing value of 47.5 by 2.3 to give a new value of +109.25 to the variable mass. + + +``` r +age <- age - 20 +``` + +This will subtract 20 from the existing value of 122 to give a new value +of 102 to the variable age. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Run the code from the previous challenge, and write a command to +compare mass to age. Is mass larger than age? + +::::::::::::::: solution + +## Solution to challenge 3 + +One way of answering this question in R is to use the `>` to set up the following: + + +``` r +mass > age +``` + +``` output +[1] TRUE +``` + +This should yield a boolean value of TRUE since 109.25 is greater than 102. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +Clean up your working environment by deleting the mass and age +variables. + +::::::::::::::: solution + +## Solution to challenge 4 + +We can use the `rm` command to accomplish this task + + +``` r +rm(age, mass) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 5 + +Install the following packages: `ggplot2`, `plyr`, `gapminder` + +::::::::::::::: solution + +## Solution to challenge 5 + +We can use the `install.packages()` command to install the required packages. + + +``` r +install.packages("ggplot2") +install.packages("plyr") +install.packages("gapminder") +``` + +An alternate solution, to install multiple packages with a single `install.packages()` command is: + + +``` r +install.packages(c("ggplot2", "plyr", "gapminder")) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::: instructor + +When installing ggplot2, it may be required for some users to use the dependencies flag as a result of lazy loading affecting the install. This suggestion is not tied to any known bug discussion, and is advised based off instructor feedback/experience in resolving stochastic occurences of errors identified through delivery of this workshop: + + +``` r +install.packages("ggplot2", dependencies = TRUE) +``` + +::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use RStudio to write and run R programs. +- R has the usual arithmetic operators and mathematical functions. +- Use `<-` to assign values to variables. +- Use `ls()` to list the variables in a program. +- Use `rm()` to delete objects in a program. +- Use `install.packages()` to install packages (libraries). + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/02-project-intro.md b/02-project-intro.md new file mode 100644 index 000000000..0571866f4 --- /dev/null +++ b/02-project-intro.md @@ -0,0 +1,284 @@ +--- +title: Project Management With RStudio +teaching: 20 +exercises: 10 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Create self-contained projects in RStudio + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I manage my projects in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +## Introduction + +The scientific process is naturally incremental, and many projects +start life as random notes, some code, then a manuscript, and +eventually everything is a bit mixed together. + + + + +Most people tend to organize their projects like this: + +![](fig/bad_layout.png){alt='Screenshot of file manager demonstrating bad project organisation'} + +There are many reasons why we should *ALWAYS* avoid this: + +1. It is really hard to tell which version of your data is + the original and which is the modified; +2. It gets really messy because it mixes files with various + extensions together; +3. It probably takes you a lot of time to actually find + things, and relate the correct figures to the exact code + that has been used to generate it; + +A good project layout will ultimately make your life easier: + +- It will help ensure the integrity of your data; +- It makes it simpler to share your code with someone else + (a lab-mate, collaborator, or supervisor); +- It allows you to easily upload your code with your manuscript submission; +- It makes it easier to pick the project back up after a break. + +## A possible solution + +Fortunately, there are tools and packages which can help you manage your work effectively. + +One of the most powerful and useful aspects of RStudio is its project management +functionality. We'll be using this today to create a self-contained, reproducible +project. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1: Creating a self-contained project + +We're going to create a new project in RStudio: + +1. Click the "File" menu button, then "New Project". +2. Click "New Directory". +3. Click "New Project". +4. Type in the name of the directory to store your project, e.g. "my\_project". +5. If available, select the checkbox for "Create a git repository." +6. Click the "Create Project" button. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +The simplest way to open an RStudio project once it has been created is to click +through your file system to get to the directory where it was saved and double +click on the `.Rproj` file. This will open RStudio and start your R session in the +same directory as the `.Rproj` file. All your data, plots and scripts will now be +relative to the project directory. RStudio projects have the added benefit of +allowing you to open multiple projects at the same time each open to its own +project directory. This allows you to keep multiple projects open without them +interfering with each other. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2: Opening an RStudio project through the file system + +1. Exit RStudio. +2. Navigate to the directory where you created a project in Challenge 1. +3. Double click on the `.Rproj` file in that directory. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Best practices for project organization + +Although there is no "best" way to lay out a project, there are some general +principles to adhere to that will make project management easier: + +### Treat data as read only + +This is probably the most important goal of setting up a project. Data is +typically time consuming and/or expensive to collect. Working with them +interactively (e.g., in Excel) where they can be modified means you are never +sure of where the data came from, or how it has been modified since collection. +It is therefore a good idea to treat your data as "read-only". + +### Data Cleaning + +In many cases your data will be "dirty": it will need significant preprocessing +to get into a format R (or any other programming language) will find useful. +This task is sometimes called "data munging". Storing these scripts in a +separate folder, and creating a second "read-only" data folder to hold the +"cleaned" data sets can prevent confusion between the two sets. + +### Treat generated output as disposable + +Anything generated by your scripts should be treated as disposable: it should +all be able to be regenerated from your scripts. + +There are lots of different ways to manage this output. Having an output folder +with different sub-directories for each separate analysis makes it easier later. +Since many analyses are exploratory and don't end up being used in the final +project, and some of the analyses get shared between projects. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Good Enough Practices for Scientific Computing + +[Good Enough Practices for Scientific Computing](https://github.com/swcarpentry/good-enough-practices-in-scientific-computing/blob/gh-pages/good-enough-practices-for-scientific-computing.pdf) gives the following recommendations for project organization: + +1. Put each project in its own directory, which is named after the project. +2. Put text documents associated with the project in the `doc` directory. +3. Put raw data and metadata in the `data` directory, and files generated during cleanup and analysis in a `results` directory. +4. Put source for the project's scripts and programs in the `src` directory, and programs brought in from elsewhere or compiled locally in the `bin` directory. +5. Name all files to reflect their content or function. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +### Separate function definition and application + +One of the more effective ways to work with R is to start by writing the code you want to run directly in a .R script, and then running the selected lines (either using the keyboard shortcuts in RStudio or clicking the "Run" button) in the interactive R console. + +When your project is in its early stages, the initial .R script file usually contains many lines +of directly executed code. As it matures, reusable chunks get pulled into their +own functions. It's a good idea to separate these functions into two separate folders; one +to store useful functions that you'll reuse across analyses and projects, and +one to store the analysis scripts. + +### Save the data in the data directory + +Now we have a good directory structure we will now place/save the data file in the `data/` directory. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Download the gapminder data from [this link to a csv file](data/gapminder_data.csv). + +1. Download the file (right mouse click on the link above -> "Save link as" / "Save file as", or click on the link and after the page loads, press Ctrl\+S or choose File -> "Save page as") +2. Make sure it's saved under the name `gapminder_data.csv` +3. Save the file in the `data/` folder within your project. + +We will load and inspect these data later. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +It is useful to get some general idea about the dataset, directly from the +command line, before loading it into R. Understanding the dataset better +will come in handy when making decisions on how to load it in R. Use the command-line +shell to answer the following questions: + +1. What is the size of the file? +2. How many rows of data does it contain? +3. What kinds of values are stored in this file? + +::::::::::::::: solution + +## Solution to Challenge 4 + +By running these commands in the shell: + + +``` sh +ls -lh data/gapminder_data.csv +``` + +``` output +-rw-r--r-- 1 runner docker 80K Nov 19 00:20 data/gapminder_data.csv +``` + +The file size is 80K. + + +``` sh +wc -l data/gapminder_data.csv +``` + +``` output +1705 data/gapminder_data.csv +``` + +There are 1705 lines. The data looks like: + + +``` sh +head data/gapminder_data.csv +``` + +``` output +country,year,pop,continent,lifeExp,gdpPercap +Afghanistan,1952,8425333,Asia,28.801,779.4453145 +Afghanistan,1957,9240934,Asia,30.332,820.8530296 +Afghanistan,1962,10267083,Asia,31.997,853.10071 +Afghanistan,1967,11537966,Asia,34.02,836.1971382 +Afghanistan,1972,13079460,Asia,36.088,739.9811058 +Afghanistan,1977,14880372,Asia,38.438,786.11336 +Afghanistan,1982,12881816,Asia,39.854,978.0114388 +Afghanistan,1987,13867957,Asia,40.822,852.3959448 +Afghanistan,1992,16317921,Asia,41.674,649.3413952 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: command line in RStudio + +The Terminal tab in the console pane provides a convenient place directly +within RStudio to interact directly with the command line. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +### Working directory + +Knowing R's current working directory is important because when you need to access other files (for example, to import a data file), R will look for them relative to the current working directory. + +Each time you create a new RStudio Project, it will create a new directory for that project. When you open an existing `.Rproj` file, it will open that project and set R's working directory to the folder that file is in. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 5 + +You can check the current working directory with the `getwd()` command, or by using the menus in RStudio. + +1. In the console, type `getwd()` ("wd" is short for "working directory") and hit Enter. +2. In the Files pane, double click on the `data` folder to open it (or navigate to any other folder you wish). To get the Files pane back to the current working directory, click "More" and then select "Go To Working Directory". + +You can change the working directory with `setwd()`, or by using RStudio menus. + +1. In the console, type `setwd("data")` and hit Enter. Type `getwd()` and hit Enter to see the new working directory. +2. In the menus at the top of the RStudio window, click the "Session" menu button, and then select "Set Working Directory" and then "Choose Directory". Next, in the windows navigator that opens, navigate back to the project directory, and click "Open". Note that a `setwd` command will automatically appear in the console. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: File does not exist errors + +When you're attempting to reference a file in your R code and you're getting errors saying the file doesn't exist, it's a good idea to check your working directory. +You need to either provide an absolute path to the file, or you need to make sure the file is saved in the working directory (or a subfolder of the working directory) and provide a relative path. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +### Version Control + +It is important to use version control with projects. Go [here for a good lesson which describes using Git with RStudio](https://swcarpentry.github.io/git-novice/14-supplemental-rstudio.html). + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use RStudio to create and manage projects with consistent layout. +- Treat raw data as read-only. +- Treat generated output as disposable. +- Separate function definition and application. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/03-seeking-help.md b/03-seeking-help.md new file mode 100644 index 000000000..3b2bbb168 --- /dev/null +++ b/03-seeking-help.md @@ -0,0 +1,345 @@ +--- +title: Seeking Help +teaching: 10 +exercises: 10 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To be able to read R help files for functions and special operators. +- To be able to use CRAN task views to identify packages to solve a problem. +- To be able to seek help from your peers. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I get help in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +## Reading Help Files + +R, and every package, provide help files for functions. The general syntax to search for help on any +function, "function\_name", from a specific function that is in a package loaded into your +namespace (your interactive R session) is: + + +``` r +?function_name +help(function_name) +``` + +For example take a look at the help file for `write.table()`, we will be using a similar function in an upcoming episode. + + +``` r +?write.table() +``` + +This will load up a help page in RStudio (or as plain text in R itself). + +Each help page is broken down into sections: + +- Description: An extended description of what the function does. +- Usage: The arguments of the function and their default values (which can be changed). +- Arguments: An explanation of the data each argument is expecting. +- Details: Any important details to be aware of. +- Value: The data the function returns. +- See Also: Any related functions you might find useful. +- Examples: Some examples for how to use the function. + +Different functions might have different sections, but these are the main ones you should be aware of. + +Notice how related functions might call for the same help file: + + +``` r +?write.table() +?write.csv() +``` + +This is because these functions have very similar applicability and often share the same arguments as inputs to the function, so package authors often choose to document them together in a single help file. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Running Examples + +From within the function help page, you can highlight code in the +Examples and hit Ctrl\+Return to run it in +RStudio console. This gives you a quick way to get a feel for +how a function works. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Reading Help Files + +One of the most daunting aspects of R is the large number of functions +available. It would be prohibitive, if not impossible to remember the +correct usage for every function you use. Luckily, using the help files +means you don't have to remember that! + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Special Operators + +To seek help on special operators, use quotes or backticks: + + +``` r +?"<-" +?`<-` +``` + +## Getting Help with Packages + +Many packages come with "vignettes": tutorials and extended example documentation. +Without any arguments, `vignette()` will list all vignettes for all installed packages; +`vignette(package="package-name")` will list all available vignettes for +`package-name`, and `vignette("vignette-name")` will open the specified vignette. + +If a package doesn't have any vignettes, you can usually find help by typing +`help("package-name")`. + +RStudio also has a set of excellent +[cheatsheets](https://rstudio.com/resources/cheatsheets/) for many packages. + +## When You Remember Part of the Function Name + +If you're not sure what package a function is in or how it's specifically spelled, you can do a fuzzy search: + + +``` r +??function_name +``` + +A fuzzy search is when you search for an approximate string match. For example, you may remember that the function +to set your working directory includes "set" in its name. You can do a fuzzy search to help you identify the function: + + +``` r +??set +``` + +## When You Have No Idea Where to Begin + +If you don't know what function or package you need to use +[CRAN Task Views](https://cran.at.r-project.org/web/views) +is a specially maintained list of packages grouped into +fields. This can be a good starting point. + +## When Your Code Doesn't Work: Seeking Help from Your Peers + +If you're having trouble using a function, 9 times out of 10, +the answers you seek have already been answered on +[Stack Overflow](https://stackoverflow.com/). You can search using +the `[r]` tag. Please make sure to see their page on +[how to ask a good question.](https://stackoverflow.com/help/how-to-ask) + +If you can't find the answer, there are a few useful functions to +help you ask your peers: + + +``` r +?dput +``` + +Will dump the data you're working with into a format that can +be copied and pasted by others into their own R session. + + +``` r +sessionInfo() +``` + +``` output +R version 4.4.2 (2024-10-31) +Platform: x86_64-pc-linux-gnu +Running under: Ubuntu 22.04.5 LTS + +Matrix products: default +BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 +LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0 + +locale: + [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 + [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 + [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C +[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C + +time zone: UTC +tzcode source: system (glibc) + +attached base packages: +[1] stats graphics grDevices utils datasets methods base + +loaded via a namespace (and not attached): +[1] compiler_4.4.2 tools_4.4.2 yaml_2.3.10 knitr_1.48 xfun_0.49 +[6] renv_1.0.11 evaluate_1.0.1 +``` + +Will print out your current version of R, as well as any packages you +have loaded. This can be useful for others to help reproduce and debug +your issue. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Look at the help page for the `c` function. What kind of vector do you +expect will be created if you evaluate the following: + + +``` r +c(1, 2, 3) +c('d', 'e', 'f') +c(1, 2, 'f') +``` + +::::::::::::::: solution + +## Solution to Challenge 1 + +The `c()` function creates a vector, in which all elements are of the +same type. In the first case, the elements are numeric, in the +second, they are characters, and in the third they are also characters: +the numeric values are "coerced" to be characters. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Look at the help for the `paste` function. You will need to use it later. +What's the difference between the `sep` and `collapse` arguments? + +::::::::::::::: solution + +## Solution to Challenge 2 + +To look at the help for the `paste()` function, use: + + +``` r +help("paste") +?paste +``` + +The difference between `sep` and `collapse` is a little +tricky. The `paste` function accepts any number of arguments, each of which +can be a vector of any length. The `sep` argument specifies the string +used between concatenated terms — by default, a space. The result is a +vector as long as the longest argument supplied to `paste`. In contrast, +`collapse` specifies that after concatenation the elements are *collapsed* +together using the given separator, the result being a single string. + +It is important to call the arguments explicitly by typing out the argument +name e.g `sep = ","` so the function understands to use the "," as a +separator and not a term to concatenate. +e.g. + + +``` r +paste(c("a","b"), "c") +``` + +``` output +[1] "a c" "b c" +``` + +``` r +paste(c("a","b"), "c", ",") +``` + +``` output +[1] "a c ," "b c ," +``` + +``` r +paste(c("a","b"), "c", sep = ",") +``` + +``` output +[1] "a,c" "b,c" +``` + +``` r +paste(c("a","b"), "c", collapse = "|") +``` + +``` output +[1] "a c|b c" +``` + +``` r +paste(c("a","b"), "c", sep = ",", collapse = "|") +``` + +``` output +[1] "a,c|b,c" +``` + +(For more information, +scroll to the bottom of the `?paste` help page and look at the +examples, or try `example('paste')`.) + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Use help to find a function (and its associated parameters) that you could +use to load data from a tabular file in which columns are delimited with "\\t" +(tab) and the decimal point is a "." (period). This check for decimal +separator is important, especially if you are working with international +colleagues, because different countries have different conventions for the +decimal point (i.e. comma vs period). +Hint: use `??"read table"` to look up functions related to reading in tabular data. + +::::::::::::::: solution + +## Solution to Challenge 3 + +The standard R function for reading tab-delimited files with a period +decimal separator is read.delim(). You can also do this with +`read.table(file, sep="\t")` (the period is the *default* decimal +separator for `read.table()`), although you may have to change +the `comment.char` argument as well if your data file contains +hash (#) characters. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Other Resources + +- [Quick R](https://www.statmethods.net/) +- [RStudio cheat sheets](https://www.rstudio.com/resources/cheatsheets/) +- [Cookbook for R](https://www.cookbook-r.com/) + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `help()` to get online help in R. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/04-data-structures-part1.md b/04-data-structures-part1.md new file mode 100644 index 000000000..3847908a7 --- /dev/null +++ b/04-data-structures-part1.md @@ -0,0 +1,1614 @@ +--- +title: Data Structures +teaching: 40 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To be able to identify the 5 main data types. +- To begin exploring data frames, and understand how they are related to vectors and lists. +- To be able to ask questions from R about the type, class, and structure of an object. +- To understand the information of the attributes "names", "class", and "dim". + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I read data in R? +- What are the basic data types in R? +- How do I represent categorical information in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +One of R's most powerful features is its ability to deal with tabular data - +such as you may already have in a spreadsheet or a CSV file. Let's start by +making a toy dataset in your `data/` directory, called `feline-data.csv`: + + +``` r +cats <- data.frame(coat = c("calico", "black", "tabby"), + weight = c(2.1, 5.0, 3.2), + likes_catnip = c(1, 0, 1)) +``` + +We can now save `cats` as a CSV file. It is good practice to call the argument +names explicitly so the function knows what default values you are changing. Here we +are setting `row.names = FALSE`. Recall you can use `?write.csv` to pull +up the help file to check out the argument names and their default values. + + +``` r +write.csv(x = cats, file = "data/feline-data.csv", row.names = FALSE) +``` + +The contents of the new file, `feline-data.csv`: + + +``` r +coat,weight,likes_catnip +calico,2.1,1 +black,5.0,0 +tabby,3.2,1 +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +### Tip: Editing Text files in R + +Alternatively, you can create `data/feline-data.csv` using a text editor (Nano), +or within RStudio with the **File -> New File -> Text File** menu item. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +We can load this into R via the following: + + +``` r +cats <- read.csv(file = "data/feline-data.csv") +cats +``` + +``` output + coat weight likes_catnip +1 calico 2.1 1 +2 black 5.0 0 +3 tabby 3.2 1 +``` + +The `read.table` function is used for reading in tabular data stored in a text +file where the columns of data are separated by punctuation characters such as +CSV files (csv = comma-separated values). Tabs and commas are the most common +punctuation characters used to separate or delimit data points in csv files. +For convenience R provides 2 other versions of `read.table`. These are: `read.csv` +for files where the data are separated with commas and `read.delim` for files +where the data are separated with tabs. Of these three functions `read.csv` is +the most commonly used. If needed it is possible to override the default +delimiting punctuation marks for both `read.csv` and `read.delim`. + +::::::::::::::::::::::::::::::::::::::::: callout + +### Check your data for factors + +In recent times, the default way how R handles textual data has changed. Text +data was interpreted by R automatically into a format called "factors". But +there is an easier format that is called "character". We will hear about +factors later, and what to use them for. For now, remember that in most cases, +they are not needed and only complicate your life, which is why newer R +versions read in text as "character". Check now if your version of R has +automatically created factors and convert them to "character" format: + +1. Check the data types of your input by typing `str(cats)` +2. In the output, look at the three-letter codes after the colons: If you see + only "num" and "chr", you can continue with the lesson and skip this box. + If you find "fct", continue to step 3. +3. Prevent R from automatically creating "factor" data. That can be done by + the following code: `options(stringsAsFactors = FALSE)`. Then, re-read + the cats table for the change to take effect. +4. You must set this option every time you restart R. To not forget this, + include it in your analysis script before you read in any data, for example + in one of the first lines. +5. For R versions greater than 4.0.0, text data is no longer converted to + factors anymore. So you can install this or a newer version to avoid this + problem. If you are working on an institute or company computer, ask your + administrator to do it. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +We can begin exploring our dataset right away, pulling out columns by specifying +them using the `$` operator: + + +``` r +cats$weight +``` + +``` output +[1] 2.1 5.0 3.2 +``` + +``` r +cats$coat +``` + +``` output +[1] "calico" "black" "tabby" +``` + +We can do other operations on the columns: + + +``` r +## Say we discovered that the scale weighs two Kg light: +cats$weight + 2 +``` + +``` output +[1] 4.1 7.0 5.2 +``` + +``` r +paste("My cat is", cats$coat) +``` + +``` output +[1] "My cat is calico" "My cat is black" "My cat is tabby" +``` + +But what about + + +``` r +cats$weight + cats$coat +``` + +``` error +Error in cats$weight + cats$coat: non-numeric argument to binary operator +``` + +Understanding what happened here is key to successfully analyzing data in R. + +### Data Types + +If you guessed that the last command will return an error because `2.1` plus +`"black"` is nonsense, you're right - and you already have some intuition for an +important concept in programming called *data types*. We can ask what type of +data something is: + + +``` r +typeof(cats$weight) +``` + +``` output +[1] "double" +``` + +There are 5 main types: `double`, `integer`, `complex`, `logical` and `character`. +For historic reasons, `double` is also called `numeric`. + + +``` r +typeof(3.14) +``` + +``` output +[1] "double" +``` + +``` r +typeof(1L) # The L suffix forces the number to be an integer, since by default R uses float numbers +``` + +``` output +[1] "integer" +``` + +``` r +typeof(1+1i) +``` + +``` output +[1] "complex" +``` + +``` r +typeof(TRUE) +``` + +``` output +[1] "logical" +``` + +``` r +typeof('banana') +``` + +``` output +[1] "character" +``` + +No matter how +complicated our analyses become, all data in R is interpreted as one of these +basic data types. This strictness has some really important consequences. + +A user has added details of another cat. This information is in the file +`data/feline-data_v2.csv`. + + +``` r +file.show("data/feline-data_v2.csv") +``` + + +``` r +coat,weight,likes_catnip +calico,2.1,1 +black,5.0,0 +tabby,3.2,1 +tabby,2.3 or 2.4,1 +``` + +Load the new cats data like before, and check what type of data we find in the +`weight` column: + + +``` r +cats <- read.csv(file="data/feline-data_v2.csv") +typeof(cats$weight) +``` + +``` output +[1] "character" +``` + +Oh no, our weights aren't the double type anymore! If we try to do the same math +we did on them before, we run into trouble: + + +``` r +cats$weight + 2 +``` + +``` error +Error in cats$weight + 2: non-numeric argument to binary operator +``` + +What happened? +The `cats` data we are working with is something called a *data frame*. Data frames +are one of the most common and versatile types of *data structures* we will work with in R. +A given column in a data frame cannot be composed of different data types. +In this case, R does not read everything in the data frame column `weight` as a *double*, therefore the entire +column data type changes to something that is suitable for everything in the column. + +When R reads a csv file, it reads it in as a *data frame*. Thus, when we loaded the `cats` +csv file, it is stored as a data frame. We can recognize data frames by the first row that +is written by the `str()` function: + + +``` r +str(cats) +``` + +``` output +'data.frame': 4 obs. of 3 variables: + $ coat : chr "calico" "black" "tabby" "tabby" + $ weight : chr "2.1" "5" "3.2" "2.3 or 2.4" + $ likes_string: int 1 0 1 1 +``` + +*Data frames* are composed of rows and columns, where each column has the +same number of rows. Different columns in a data frame can be made up of different +data types (this is what makes them so versatile), but everything in a given +column needs to be the same type (e.g., vector, factor, or list). + +Let's explore more about different data structures and how they behave. +For now, let's remove that extra line from our cats data and reload it, +while we investigate this behavior further: + +feline-data.csv: + +``` +coat,weight,likes_catnip +calico,2.1,1 +black,5.0,0 +tabby,3.2,1 +``` + +And back in RStudio: + + +``` r +cats <- read.csv(file="data/feline-data.csv") +``` + + + +### Vectors and Type Coercion + +To better understand this behavior, let's meet another of the data structures: +the *vector*. + + +``` r +my_vector <- vector(length = 3) +my_vector +``` + +``` output +[1] FALSE FALSE FALSE +``` + +A vector in R is essentially an ordered list of things, with the special +condition that *everything in the vector must be the same basic data type*. If +you don't choose the datatype, it'll default to `logical`; or, you can declare +an empty vector of whatever type you like. + + +``` r +another_vector <- vector(mode='character', length=3) +another_vector +``` + +``` output +[1] "" "" "" +``` + +You can check if something is a vector: + + +``` r +str(another_vector) +``` + +``` output + chr [1:3] "" "" "" +``` + +The somewhat cryptic output from this command indicates the basic data type +found in this vector - in this case `chr`, character; an indication of the +number of things in the vector - actually, the indexes of the vector, in this +case `[1:3]`; and a few examples of what's actually in the vector - in this case +empty character strings. If we similarly do + + +``` r +str(cats$weight) +``` + +``` output + num [1:3] 2.1 5 3.2 +``` + +we see that `cats$weight` is a vector, too - *the columns of data we load into R +data.frames are all vectors*, and that's the root of why R forces everything in +a column to be the same basic data type. + +:::::::::::::::::::::::::::::::::::::: discussion + +### Discussion 1 + +Why is R so opinionated about what we put in our columns of data? +How does this help us? + +::::::::::::::: solution + +### Discussion 1 + +By keeping everything in a column the same, we allow ourselves to make simple +assumptions about our data; if you can interpret one entry in the column as a +number, then you can interpret *all* of them as numbers, so we don't have to +check every time. This consistency is what people mean when they talk about +*clean data*; in the long run, strict consistency goes a long way to making +our lives easier in R. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +#### Coercion by combining vectors + +You can also make vectors with explicit contents with the combine function: + + +``` r +combine_vector <- c(2,6,3) +combine_vector +``` + +``` output +[1] 2 6 3 +``` + +Given what we've learned so far, what do you think the following will produce? + + +``` r +quiz_vector <- c(2,6,'3') +``` + +This is something called *type coercion*, and it is the source of many surprises +and the reason why we need to be aware of the basic data types and how R will +interpret them. When R encounters a mix of types (here double and character) to +be combined into a single vector, it will force them all to be the same +type. Consider: + + +``` r +coercion_vector <- c('a', TRUE) +coercion_vector +``` + +``` output +[1] "a" "TRUE" +``` + +``` r +another_coercion_vector <- c(0, TRUE) +another_coercion_vector +``` + +``` output +[1] 0 1 +``` + +#### The type hierarchy + +The coercion rules go: `logical` -> `integer` -> `double` ("`numeric`") -> +`complex` -> `character`, where -> can be read as *are transformed into*. For +example, combining `logical` and `character` transforms the result to +`character`: + + +``` r +c('a', TRUE) +``` + +``` output +[1] "a" "TRUE" +``` + +A quick way to recognize `character` vectors is by the quotes that enclose them +when they are printed. + +You can try to force +coercion against this flow using the `as.` functions: + + +``` r +character_vector_example <- c('0','2','4') +character_vector_example +``` + +``` output +[1] "0" "2" "4" +``` + +``` r +character_coerced_to_double <- as.double(character_vector_example) +character_coerced_to_double +``` + +``` output +[1] 0 2 4 +``` + +``` r +double_coerced_to_logical <- as.logical(character_coerced_to_double) +double_coerced_to_logical +``` + +``` output +[1] FALSE TRUE TRUE +``` + +As you can see, some surprising things can happen when R forces one basic data +type into another! Nitty-gritty of type coercion aside, the point is: if your +data doesn't look like what you thought it was going to look like, type coercion +may well be to blame; make sure everything is the same type in your vectors and +your columns of data.frames, or you will get nasty surprises! + +But coercion can also be very useful! For example, in our `cats` data +`likes_catnip` is numeric, but we know that the 1s and 0s actually represent +`TRUE` and `FALSE` (a common way of representing them). We should use the +`logical` datatype here, which has two states: `TRUE` or `FALSE`, which is +exactly what our data represents. We can 'coerce' this column to be `logical` by +using the `as.logical` function: + + +``` r +cats$likes_catnip +``` + +``` output +[1] 1 0 1 +``` + +``` r +cats$likes_catnip <- as.logical(cats$likes_catnip) +cats$likes_catnip +``` + +``` output +[1] TRUE FALSE TRUE +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 1 + +An important part of every data analysis is cleaning the input data. If you +know that the input data is all of the same format, (e.g. numbers), your +analysis is much easier! Clean the cat data set from the chapter about +type coercion. + +#### Copy the code template + +Create a new script in RStudio and copy and paste the following code. Then +move on to the tasks below, which help you to fill in the gaps (\_\_\_\_\_\_). + +``` +# Read data +cats <- read.csv("data/feline-data_v2.csv") + +# 1. Print the data +_____ + +# 2. Show an overview of the table with all data types +_____(cats) + +# 3. The "weight" column has the incorrect data type __________. +# The correct data type is: ____________. + +# 4. Correct the 4th weight data point with the mean of the two given values +cats$weight[4] <- 2.35 +# print the data again to see the effect +cats + +# 5. Convert the weight to the right data type +cats$weight <- ______________(cats$weight) + +# Calculate the mean to test yourself +mean(cats$weight) + +# If you see the correct mean value (and not NA), you did the exercise +# correctly! +``` + +### Instructions for the tasks + +#### 1\. Print the data + +Execute the first statement (`read.csv(...)`). Then print the data to the +console + +::::::::::::::: solution + +### Tip 1.1 + +Show the content of any variable by typing its name. + + +### Solution to Challenge 1.1 + +Two correct solutions: + +``` +cats +print(cats) +``` + +::::::::::::::::::::::::: + +#### 2\. Overview of the data types + +The data type of your data is as important as the data itself. Use a +function we saw earlier to print out the data types of all columns of the +`cats` table. + +::::::::::::::: solution + +### Tip 1.2 + +In the chapter "Data types" we saw two functions that can show data types. +One printed just a single word, the data type name. The other printed +a short form of the data type, and the first few values. We need the second +here. + + +::::::::::::::::::::::::: + +> ### Solution to Challenge 1.2 +> +> ``` +> str(cats) +> ``` + +#### 3\. Which data type do we need? + +The shown data type is not the right one for this data (weight of +a cat). Which data type do we need? + +- Why did the `read.csv()` function not choose the correct data type? +- Fill in the gap in the comment with the correct data type for cat weight! + +::::::::::::::: solution + +### Tip 1.3 + +Scroll up to the section about the [type hierarchy](#the-type-hierarchy) +to review the available data types + + +::::::::::::::::::::::::: + +::::::::::::::: solution + +### Solution to Challenge 1.3 + +- Weight is expressed on a continuous scale (real numbers). The R + data type for this is "double" (also known as "numeric"). +- The fourth row has the value "2.3 or 2.4". That is not a number + but two, and an english word. Therefore, the "character" data type + is chosen. The whole column is now text, because all values in the same + columns have to be the same data type. + + +::::::::::::::::::::::::: + +#### 4\. Correct the problematic value + +The code to assign a new weight value to the problematic fourth row is given. +Think first and then execute it: What will be the data type after assigning +a number like in this example? +You can check the data type after executing to see if you were right. + +::::::::::::::: solution + +### Tip 1.4 + +Revisit the hierarchy of data types when two different data types are +combined. + + +::::::::::::::::::::::::: + +> ### Solution to challenge 1.4 +> +> The data type of the column "weight" is "character". The assigned data +> type is "double". Combining two data types yields the data type that is +> higher in the following hierarchy: +> +> ``` +> logical < integer < double < complex < character +> ``` +> +> Therefore, the column is still of type character! We need to manually +> convert it to "double". +> {: .solution} + +#### 5\. Convert the column "weight" to the correct data type + +Cat weight are numbers. But the column does not have this data type yet. +Coerce the column to floating point numbers. + +::::::::::::::: solution + +### Tip 1.5 + +The functions to convert data types start with `as.`. You can look +for the function further up in the manuscript or use the RStudio +auto-complete function: Type "`as.`" and then press the TAB key. + + +::::::::::::::::::::::::: + +> ### Solution to Challenge 1.5 +> +> There are two functions that are synonymous for historic reasons: +> +> ``` +> cats$weight <- as.double(cats$weight) +> cats$weight <- as.numeric(cats$weight) +> ``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +### Some basic vector functions + +The combine function, `c()`, will also append things to an existing vector: + + +``` r +ab_vector <- c('a', 'b') +ab_vector +``` + +``` output +[1] "a" "b" +``` + +``` r +combine_example <- c(ab_vector, 'SWC') +combine_example +``` + +``` output +[1] "a" "b" "SWC" +``` + +You can also make series of numbers: + + +``` r +mySeries <- 1:10 +mySeries +``` + +``` output + [1] 1 2 3 4 5 6 7 8 9 10 +``` + +``` r +seq(10) +``` + +``` output + [1] 1 2 3 4 5 6 7 8 9 10 +``` + +``` r +seq(1,10, by=0.1) +``` + +``` output + [1] 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 +[16] 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 +[31] 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 +[46] 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 +[61] 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 +[76] 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 +[91] 10.0 +``` + +We can ask a few questions about vectors: + + +``` r +sequence_example <- 20:25 +head(sequence_example, n=2) +``` + +``` output +[1] 20 21 +``` + +``` r +tail(sequence_example, n=4) +``` + +``` output +[1] 22 23 24 25 +``` + +``` r +length(sequence_example) +``` + +``` output +[1] 6 +``` + +``` r +typeof(sequence_example) +``` + +``` output +[1] "integer" +``` + +We can get individual elements of a vector by using the bracket notation: + + +``` r +first_element <- sequence_example[1] +first_element +``` + +``` output +[1] 20 +``` + +To change a single element, use the bracket on the other side of the arrow: + + +``` r +sequence_example[1] <- 30 +sequence_example +``` + +``` output +[1] 30 21 22 23 24 25 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 2 + +Start by making a vector with the numbers 1 through 26. +Then, multiply the vector by 2. + +::::::::::::::: solution + +### Solution to Challenge 2 + + +``` r +x <- 1:26 +x <- x * 2 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +### Lists + +Another data structure you'll want in your bag of tricks is the `list`. A list +is simpler in some ways than the other types, because you can put anything you +want in it. Remember *everything in the vector must be of the same basic data type*, +but a list can have different data types: + + +``` r +list_example <- list(1, "a", TRUE, 1+4i) +list_example +``` + +``` output +[[1]] +[1] 1 + +[[2]] +[1] "a" + +[[3]] +[1] TRUE + +[[4]] +[1] 1+4i +``` + +When printing the object structure with `str()`, we see the data types of all +elements: + + +``` r +str(list_example) +``` + +``` output +List of 4 + $ : num 1 + $ : chr "a" + $ : logi TRUE + $ : cplx 1+4i +``` + +What is the use of lists? They can **organize data of different types**. For +example, you can organize different tables that belong together, similar to +spreadsheets in Excel. But there are many other uses, too. + +We will see another example that will maybe surprise you in the next chapter. + +To retrieve one of the elements of a list, use the **double bracket**: + + +``` r +list_example[[2]] +``` + +``` output +[1] "a" +``` + +The elements of lists also can have **names**, they can be given by prepending +them to the values, separated by an equals sign: + + +``` r +another_list <- list(title = "Numbers", numbers = 1:10, data = TRUE ) +another_list +``` + +``` output +$title +[1] "Numbers" + +$numbers + [1] 1 2 3 4 5 6 7 8 9 10 + +$data +[1] TRUE +``` + +This results in a **named list**. Now we have a new function of our object! +We can access single elements by an additional way! + + +``` r +another_list$title +``` + +``` output +[1] "Numbers" +``` + +## Names + +With names, we can give meaning to elements. It is the first time that we do not +only have the **data**, but also explaining information. It is *metadata* +that can be stuck to the object like a label. In R, this is called an +**attribute**. Some attributes enable us to do more with our +object, for example, like here, accessing an element by a self-defined name. + +### Accessing vectors and lists by name + +We have already seen how to generate a named list. The way to generate a named +vector is very similar. You have seen this function before: + + +``` r +pizza_price <- c( pizzasubito = 5.64, pizzafresh = 6.60, callapizza = 4.50 ) +``` + +The way to retrieve elements is different, though: + + +``` r +pizza_price["pizzasubito"] +``` + +``` output +pizzasubito + 5.64 +``` + +The approach used for the list does not work: + + +``` r +pizza_price$pizzafresh +``` + +``` error +Error in pizza_price$pizzafresh: $ operator is invalid for atomic vectors +``` + +It will pay off if you remember this error message, you will meet it in your own +analyses. It means that you have just tried accessing an element like it was in +a list, but it is actually in a vector. + +### Accessing and changing names + +If you are only interested in the names, use the `names()` function: + + +``` r +names(pizza_price) +``` + +``` output +[1] "pizzasubito" "pizzafresh" "callapizza" +``` + +We have seen how to access and change single elements of a vector. The same is +possible for names: + + +``` r +names(pizza_price)[3] +``` + +``` output +[1] "callapizza" +``` + +``` r +names(pizza_price)[3] <- "call-a-pizza" +pizza_price +``` + +``` output + pizzasubito pizzafresh call-a-pizza + 5.64 6.60 4.50 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 3 + +- What is the data type of the names of `pizza_price`? You can find out + using the `str()` or `typeof()` functions. + +::::::::::::::: solution + +### Solution to Challenge 3 + +You get the names of an object by wrapping the object name inside +`names(...)`. Similarly, you get the data type of the names by again +wrapping the whole code in `typeof(...)`: + +``` +typeof(names(pizza)) +``` + +alternatively, use a new variable if this is easier for you to read: + +``` +n <- names(pizza) +typeof(n) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 4 + +Instead of just changing some of the names a vector/list already has, you can +also set all names of an object by writing code like (replace ALL CAPS text): + +``` +names( OBJECT ) <- CHARACTER_VECTOR +``` + +Create a vector that gives the number for each letter in the alphabet! + +1. Generate a vector called `letter_no` with the sequence of numbers from 1 + to 26! +2. R has a built-in object called `LETTERS`. It is a 26-character vector, from + A to Z. Set the names of the number sequence to this 26 letters +3. Test yourself by calling `letter_no["B"]`, which should give you the number + 2! + +::::::::::::::: solution + +### Solution to Challenge 4 + +``` +letter_no <- 1:26 # or seq(1,26) +names(letter_no) <- LETTERS +letter_no["B"] +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Data frames + +We have data frames at the very beginning of this lesson, they represent +a table of data. We didn't go much further into detail with our example cat +data frame: + + +``` r +cats +``` + +``` output + coat weight likes_catnip +1 calico 2.1 TRUE +2 black 5.0 FALSE +3 tabby 3.2 TRUE +``` + +We can now understand something a bit surprising in our data.frame; what happens +if we run: + + +``` r +typeof(cats) +``` + +``` output +[1] "list" +``` + +We see that data.frames look like lists 'under the hood'. Think again what we +heard about what lists can be used for: + +> Lists organize data of different types + +Columns of a data frame are vectors of different types, that are organized +by belonging to the same table. + +A data.frame is really a list of vectors. It is a special list in which all the +vectors must have the same length. + +How is this "special"-ness written into the object, so that R does not treat it +like any other list, but as a table? + + +``` r +class(cats) +``` + +``` output +[1] "data.frame" +``` + +A **class**, just like names, is an attribute attached to the object. It tells +us what this object means for humans. + +You might wonder: Why do we need another what-type-of-object-is-this-function? +We already have `typeof()`? That function tells us how the object is +**constructed in the computer**. The `class` is the **meaning of the object for +humans**. Consequently, what `typeof()` returns is *fixed* in R (mainly the +five data types), whereas the output of `class()` is *diverse* and *extendable* +by R packages. + +In our `cats` example, we have an integer, a double and a logical variable. As +we have seen already, each column of data.frame is a vector. + + +``` r +cats$coat +``` + +``` output +[1] "calico" "black" "tabby" +``` + +``` r +cats[,1] +``` + +``` output +[1] "calico" "black" "tabby" +``` + +``` r +typeof(cats[,1]) +``` + +``` output +[1] "character" +``` + +``` r +str(cats[,1]) +``` + +``` output + chr [1:3] "calico" "black" "tabby" +``` + +Each row is an *observation* of different variables, itself a data.frame, and +thus can be composed of elements of different types. + + +``` r +cats[1,] +``` + +``` output + coat weight likes_catnip +1 calico 2.1 TRUE +``` + +``` r +typeof(cats[1,]) +``` + +``` output +[1] "list" +``` + +``` r +str(cats[1,]) +``` + +``` output +'data.frame': 1 obs. of 3 variables: + $ coat : chr "calico" + $ weight : num 2.1 + $ likes_catnip: logi TRUE +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 5 + +There are several subtly different ways to call variables, observations and +elements from data.frames: + +- `cats[1]` +- `cats[[1]]` +- `cats$coat` +- `cats["coat"]` +- `cats[1, 1]` +- `cats[, 1]` +- `cats[1, ]` + +Try out these examples and explain what is returned by each one. + +*Hint:* Use the function `typeof()` to examine what is returned in each case. + +::::::::::::::: solution + +### Solution to Challenge 5 + + +``` r +cats[1] +``` + +``` output + coat +1 calico +2 black +3 tabby +``` + +We can think of a data frame as a list of vectors. The single brace `[1]` +returns the first slice of the list, as another list. In this case it is the +first column of the data frame. + + +``` r +cats[[1]] +``` + +``` output +[1] "calico" "black" "tabby" +``` + +The double brace `[[1]]` returns the contents of the list item. In this case +it is the contents of the first column, a *vector* of type *character*. + + +``` r +cats$coat +``` + +``` output +[1] "calico" "black" "tabby" +``` + +This example uses the `$` character to address items by name. *coat* is the +first column of the data frame, again a *vector* of type *character*. + + +``` r +cats["coat"] +``` + +``` output + coat +1 calico +2 black +3 tabby +``` + +Here we are using a single brace `["coat"]` replacing the index number with +the column name. Like example 1, the returned object is a *list*. + + +``` r +cats[1, 1] +``` + +``` output +[1] "calico" +``` + +This example uses a single brace, but this time we provide row and column +coordinates. The returned object is the value in row 1, column 1. The object +is a *vector* of type *character*. + + +``` r +cats[, 1] +``` + +``` output +[1] "calico" "black" "tabby" +``` + +Like the previous example we use single braces and provide row and column +coordinates. The row coordinate is not specified, R interprets this missing +value as all the elements in this *column* and returns them as a *vector*. + + +``` r +cats[1, ] +``` + +``` output + coat weight likes_catnip +1 calico 2.1 TRUE +``` + +Again we use the single brace with row and column coordinates. The column +coordinate is not specified. The return value is a *list* containing all the +values in the first row. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +### Tip: Renaming data frame columns + +Data frames have column names, which can be accessed with the `names()` function. + + +``` r +names(cats) +``` + +``` output +[1] "coat" "weight" "likes_catnip" +``` + +If you want to rename the second column of `cats`, you can assign a new name to the second element of `names(cats)`. + + +``` r +names(cats)[2] <- "weight_kg" +cats +``` + +``` output + coat weight_kg likes_catnip +1 calico 2.1 TRUE +2 black 5.0 FALSE +3 tabby 3.2 TRUE +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +### Matrices + +Last but not least is the matrix. We can declare a matrix full of zeros: + + +``` r +matrix_example <- matrix(0, ncol=6, nrow=3) +matrix_example +``` + +``` output + [,1] [,2] [,3] [,4] [,5] [,6] +[1,] 0 0 0 0 0 0 +[2,] 0 0 0 0 0 0 +[3,] 0 0 0 0 0 0 +``` + +What makes it special is the `dim()` attribute: + + +``` r +dim(matrix_example) +``` + +``` output +[1] 3 6 +``` + +And similar to other data structures, we can ask things about our matrix: + + +``` r +typeof(matrix_example) +``` + +``` output +[1] "double" +``` + +``` r +class(matrix_example) +``` + +``` output +[1] "matrix" "array" +``` + +``` r +str(matrix_example) +``` + +``` output + num [1:3, 1:6] 0 0 0 0 0 0 0 0 0 0 ... +``` + +``` r +nrow(matrix_example) +``` + +``` output +[1] 3 +``` + +``` r +ncol(matrix_example) +``` + +``` output +[1] 6 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 6 + +What do you think will be the result of +`length(matrix_example)`? +Try it. +Were you right? Why / why not? + +::::::::::::::: solution + +### Solution to Challenge 6 + +What do you think will be the result of +`length(matrix_example)`? + + +``` r +matrix_example <- matrix(0, ncol=6, nrow=3) +length(matrix_example) +``` + +``` output +[1] 18 +``` + +Because a matrix is a vector with added dimension attributes, `length` +gives you the total number of elements in the matrix. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 7 + +Make another matrix, this time containing the numbers 1:50, +with 5 columns and 10 rows. +Did the `matrix` function fill your matrix by column, or by +row, as its default behaviour? +See if you can figure out how to change this. +(hint: read the documentation for `matrix`!) + +::::::::::::::: solution + +### Solution to Challenge 7 + +Make another matrix, this time containing the numbers 1:50, +with 5 columns and 10 rows. +Did the `matrix` function fill your matrix by column, or by +row, as its default behaviour? +See if you can figure out how to change this. +(hint: read the documentation for `matrix`!) + + +``` r +x <- matrix(1:50, ncol=5, nrow=10) +x <- matrix(1:50, ncol=5, nrow=10, byrow = TRUE) # to fill by row +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 8 + +Create a list of length two containing a character vector for each of the sections in this part of the workshop: + +- Data types +- Data structures + +Populate each character vector with the names of the data types and data +structures we've seen so far. + +::::::::::::::: solution + +### Solution to Challenge 8 + + +``` r +dataTypes <- c('double', 'complex', 'integer', 'character', 'logical') +dataStructures <- c('data.frame', 'vector', 'list', 'matrix') +answer <- list(dataTypes, dataStructures) +``` + +Note: it's nice to make a list in big writing on the board or taped to the wall +listing all of these types and structures - leave it up for the rest of the workshop +to remind people of the importance of these basics. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +### Challenge 9 + +Consider the R output of the matrix below: + + +``` output + [,1] [,2] +[1,] 4 1 +[2,] 9 5 +[3,] 10 7 +``` + +What was the correct command used to write this matrix? Examine +each command and try to figure out the correct one before typing them. +Think about what matrices the other commands will produce. + +1. `matrix(c(4, 1, 9, 5, 10, 7), nrow = 3)` +2. `matrix(c(4, 9, 10, 1, 5, 7), ncol = 2, byrow = TRUE)` +3. `matrix(c(4, 9, 10, 1, 5, 7), nrow = 2)` +4. `matrix(c(4, 1, 9, 5, 10, 7), ncol = 2, byrow = TRUE)` + +::::::::::::::: solution + +### Solution to Challenge 9 + +Consider the R output of the matrix below: + + +``` output + [,1] [,2] +[1,] 4 1 +[2,] 9 5 +[3,] 10 7 +``` + +What was the correct command used to write this matrix? Examine +each command and try to figure out the correct one before typing them. +Think about what matrices the other commands will produce. + + +``` r +matrix(c(4, 1, 9, 5, 10, 7), ncol = 2, byrow = TRUE) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `read.csv` to read tabular data in R. +- The basic data types in R are double, integer, complex, logical, and character. +- Data structures such as data frames or matrices are built on top of lists and vectors, with some added attributes. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/05-data-structures-part2.md b/05-data-structures-part2.md new file mode 100644 index 000000000..c450668c8 --- /dev/null +++ b/05-data-structures-part2.md @@ -0,0 +1,592 @@ +--- +title: Exploring Data Frames +teaching: 20 +exercises: 10 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Add and remove rows or columns. +- Append two data frames. +- Display basic properties of data frames including size and class of the columns, names, and first few rows. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I manipulate a data frame? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +At this point, you've seen it all: in the last lesson, we toured all the basic +data types and data structures in R. Everything you do will be a manipulation of +those tools. But most of the time, the star of the show is the data frame—the table that we created by loading information from a csv file. In this lesson, we'll learn a few more things +about working with data frames. + +## Adding columns and rows in data frames + +We already learned that the columns of a data frame are vectors, so that our +data are consistent in type throughout the columns. As such, if we want to add a +new column, we can start by making a new vector: + + + + +``` r +age <- c(2, 3, 5) +cats +``` + +``` output + coat weight likes_catnip +1 calico 2.1 1 +2 black 5.0 0 +3 tabby 3.2 1 +``` + +We can then add this as a column via: + + +``` r +cbind(cats, age) +``` + +``` output + coat weight likes_catnip age +1 calico 2.1 1 2 +2 black 5.0 0 3 +3 tabby 3.2 1 5 +``` + +Note that if we tried to add a vector of ages with a different number of entries than the number of rows in the data frame, it would fail: + + +``` r +age <- c(2, 3, 5, 12) +cbind(cats, age) +``` + +``` error +Error in data.frame(..., check.names = FALSE): arguments imply differing number of rows: 3, 4 +``` + +``` r +age <- c(2, 3) +cbind(cats, age) +``` + +``` error +Error in data.frame(..., check.names = FALSE): arguments imply differing number of rows: 3, 2 +``` + +Why didn't this work? Of course, R wants to see one element in our new column +for every row in the table: + + +``` r +nrow(cats) +``` + +``` output +[1] 3 +``` + +``` r +length(age) +``` + +``` output +[1] 2 +``` + +So for it to work we need to have `nrow(cats)` = `length(age)`. Let's overwrite the content of cats with our new data frame. + + +``` r +age <- c(2, 3, 5) +cats <- cbind(cats, age) +``` + +Now how about adding rows? We already know that the rows of a +data frame are lists: + + +``` r +newRow <- list("tortoiseshell", 3.3, TRUE, 9) +cats <- rbind(cats, newRow) +``` + +Let's confirm that our new row was added correctly. + + +``` r +cats +``` + +``` output + coat weight likes_catnip age +1 calico 2.1 1 2 +2 black 5.0 0 3 +3 tabby 3.2 1 5 +4 tortoiseshell 3.3 1 9 +``` + + +## Removing rows + +We now know how to add rows and columns to our data frame in R. Now let's learn to remove rows. + + +``` r +cats +``` + +``` output + coat weight likes_catnip age +1 calico 2.1 1 2 +2 black 5.0 0 3 +3 tabby 3.2 1 5 +4 tortoiseshell 3.3 1 9 +``` + +We can ask for a data frame minus the last row: + + +``` r +cats[-4, ] +``` + +``` output + coat weight likes_catnip age +1 calico 2.1 1 2 +2 black 5.0 0 3 +3 tabby 3.2 1 5 +``` + +Notice the comma with nothing after it to indicate that we want to drop the entire fourth row. + +Note: we could also remove several rows at once by putting the row numbers +inside of a vector, for example: `cats[c(-3,-4), ]` + + +## Removing columns + +We can also remove columns in our data frame. What if we want to remove the column "age". We can remove it in two ways, by variable number or by index. + + +``` r +cats[,-4] +``` + +``` output + coat weight likes_catnip +1 calico 2.1 1 +2 black 5.0 0 +3 tabby 3.2 1 +4 tortoiseshell 3.3 1 +``` + +Notice the comma with nothing before it, indicating we want to keep all of the rows. + +Alternatively, we can drop the column by using the index name and the `%in%` operator. The `%in%` operator goes through each element of its left argument, in this case the names of `cats`, and asks, "Does this element occur in the second argument?" + + +``` r +drop <- names(cats) %in% c("age") +cats[,!drop] +``` + +``` output + coat weight likes_catnip +1 calico 2.1 1 +2 black 5.0 0 +3 tabby 3.2 1 +4 tortoiseshell 3.3 1 +``` + +We will cover subsetting with logical operators like `%in%` in more detail in the next episode. See the section [Subsetting through other logical operations](06-data-subsetting.Rmd) + +## Appending to a data frame + +The key to remember when adding data to a data frame is that *columns are +vectors and rows are lists.* We can also glue two data frames +together with `rbind`: + + +``` r +cats <- rbind(cats, cats) +cats +``` + +``` output + coat weight likes_catnip age +1 calico 2.1 1 2 +2 black 5.0 0 3 +3 tabby 3.2 1 5 +4 tortoiseshell 3.3 1 9 +5 calico 2.1 1 2 +6 black 5.0 0 3 +7 tabby 3.2 1 5 +8 tortoiseshell 3.3 1 9 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +You can create a new data frame right from within R with the following syntax: + + +``` r +df <- data.frame(id = c("a", "b", "c"), + x = 1:3, + y = c(TRUE, TRUE, FALSE)) +``` + +Make a data frame that holds the following information for yourself: + +- first name +- last name +- lucky number + +Then use `rbind` to add an entry for the people sitting beside you. +Finally, use `cbind` to add a column with each person's answer to the question, "Is it time for coffee break?" + +::::::::::::::: solution + +## Solution to Challenge 1 + + +``` r +df <- data.frame(first = c("Grace"), + last = c("Hopper"), + lucky_number = c(0)) +df <- rbind(df, list("Marie", "Curie", 238) ) +df <- cbind(df, coffeetime = c(TRUE,TRUE)) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Realistic example + +So far, you have seen the basics of manipulating data frames with our cat data; +now let's use those skills to digest a more realistic dataset. Let's read in the +`gapminder` dataset that we downloaded previously: + + +``` r +gapminder <- read.csv("data/gapminder_data.csv") +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Miscellaneous Tips + +- Another type of file you might encounter are tab-separated value files (.tsv). To specify a tab as a separator, use `"\\t"` or `read.delim()`. + +- Files can also be downloaded directly from the Internet into a local + folder of your choice onto your computer using the `download.file` function. + The `read.csv` function can then be executed to read the downloaded file from the download location, for example, + + +``` r +download.file("https://raw.githubusercontent.com/swcarpentry/r-novice-gapminder/main/episodes/data/gapminder_data.csv", destfile = "data/gapminder_data.csv") +gapminder <- read.csv("data/gapminder_data.csv") +``` + +- Alternatively, you can also read in files directly into R from the Internet by replacing the file paths with a web address in `read.csv`. One should note that in doing this no local copy of the csv file is first saved onto your computer. For example, + + +``` r +gapminder <- read.csv("https://raw.githubusercontent.com/swcarpentry/r-novice-gapminder/main/episodes/data/gapminder_data.csv") +``` + +- You can read directly from excel spreadsheets without + converting them to plain text first by using the [readxl](https://cran.r-project.org/package=readxl) package. + +- The argument "stringsAsFactors" can be useful to tell R how to read strings either as factors or as character strings. In R versions after 4.0, all strings are read-in as characters by default, but in earlier versions of R, strings are read-in as factors by default. For more information, see the call-out in [the previous episode](https://swcarpentry.github.io/r-novice-gapminder/04-data-structures-part1.html#check-your-data-for-factors). + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Let's investigate gapminder a bit; the first thing we should always do is check +out what the data looks like with `str`: + + +``` r +str(gapminder) +``` + +``` output +'data.frame': 1704 obs. of 6 variables: + $ country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ... + $ year : int 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ... + $ pop : num 8425333 9240934 10267083 11537966 13079460 ... + $ continent: chr "Asia" "Asia" "Asia" "Asia" ... + $ lifeExp : num 28.8 30.3 32 34 36.1 ... + $ gdpPercap: num 779 821 853 836 740 ... +``` + +An additional method for examining the structure of gapminder is to use the `summary` function. This function can be used on various objects in R. For data frames, `summary` yields a numeric, tabular, or descriptive summary of each column. Numeric or integer columns are described by the descriptive statistics (quartiles and mean), and character columns by its length, class, and mode. + + +``` r +summary(gapminder) +``` + +``` output + country year pop continent + Length:1704 Min. :1952 Min. :6.001e+04 Length:1704 + Class :character 1st Qu.:1966 1st Qu.:2.794e+06 Class :character + Mode :character Median :1980 Median :7.024e+06 Mode :character + Mean :1980 Mean :2.960e+07 + 3rd Qu.:1993 3rd Qu.:1.959e+07 + Max. :2007 Max. :1.319e+09 + lifeExp gdpPercap + Min. :23.60 Min. : 241.2 + 1st Qu.:48.20 1st Qu.: 1202.1 + Median :60.71 Median : 3531.8 + Mean :59.47 Mean : 7215.3 + 3rd Qu.:70.85 3rd Qu.: 9325.5 + Max. :82.60 Max. :113523.1 +``` + +Along with the `str` and `summary` functions, we can examine individual columns of the data frame with our `typeof` function: + + +``` r +typeof(gapminder$year) +``` + +``` output +[1] "integer" +``` + +``` r +typeof(gapminder$country) +``` + +``` output +[1] "character" +``` + +``` r +str(gapminder$country) +``` + +``` output + chr [1:1704] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ... +``` + +We can also interrogate the data frame for information about its dimensions; +remembering that `str(gapminder)` said there were 1704 observations of 6 +variables in gapminder, what do you think the following will produce, and why? + + +``` r +length(gapminder) +``` + +``` output +[1] 6 +``` + +A fair guess would have been to say that the length of a data frame would be the +number of rows it has (1704), but this is not the case; remember, a data frame +is a *list of vectors and factors*: + + +``` r +typeof(gapminder) +``` + +``` output +[1] "list" +``` + +When `length` gave us 6, it's because gapminder is built out of a list of 6 +columns. To get the number of rows and columns in our dataset, try: + + +``` r +nrow(gapminder) +``` + +``` output +[1] 1704 +``` + +``` r +ncol(gapminder) +``` + +``` output +[1] 6 +``` + +Or, both at once: + + +``` r +dim(gapminder) +``` + +``` output +[1] 1704 6 +``` + +We'll also likely want to know what the titles of all the columns are, so we can +ask for them later: + + +``` r +colnames(gapminder) +``` + +``` output +[1] "country" "year" "pop" "continent" "lifeExp" "gdpPercap" +``` + +At this stage, it's important to ask ourselves if the structure R is reporting +matches our intuition or expectations; do the basic data types reported for each +column make sense? If not, we need to sort any problems out now before they turn +into bad surprises down the road, using what we've learned about how R +interprets data, and the importance of *strict consistency* in how we record our +data. + +Once we're happy that the data types and structures seem reasonable, it's time +to start digging into our data proper. Check out the first few lines: + + +``` r +head(gapminder) +``` + +``` output + country year pop continent lifeExp gdpPercap +1 Afghanistan 1952 8425333 Asia 28.801 779.4453 +2 Afghanistan 1957 9240934 Asia 30.332 820.8530 +3 Afghanistan 1962 10267083 Asia 31.997 853.1007 +4 Afghanistan 1967 11537966 Asia 34.020 836.1971 +5 Afghanistan 1972 13079460 Asia 36.088 739.9811 +6 Afghanistan 1977 14880372 Asia 38.438 786.1134 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +It's good practice to also check the last few lines of your data and some in the middle. How would you do this? + +Searching for ones specifically in the middle isn't too hard, but we could ask for a few lines at random. How would you code this? + +::::::::::::::: solution + +## Solution to Challenge 2 + +To check the last few lines it's relatively simple as R already has a function for this: + +```r +tail(gapminder) +tail(gapminder, n = 15) +``` + +What about a few arbitrary rows just in case something is odd in the middle? + +## Tip: There are several ways to achieve this. + +The solution here presents one form of using nested functions, i.e. a function passed as an argument to another function. This might sound like a new concept, but you are already using it! +Remember my\_dataframe[rows, cols] will print to screen your data frame with the number of rows and columns you asked for (although you might have asked for a range or named columns for example). How would you get the last row if you don't know how many rows your data frame has? R has a function for this. What about getting a (pseudorandom) sample? R also has a function for this. + +```r +gapminder[sample(nrow(gapminder), 5), ] +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +To make sure our analysis is reproducible, we should put the code +into a script file so we can come back to it later. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Go to file -> new file -> R script, and write an R script +to load in the gapminder dataset. Put it in the `scripts/` +directory and add it to version control. + +Run the script using the `source` function, using the file path +as its argument (or by pressing the "source" button in RStudio). + +::::::::::::::: solution + +## Solution to Challenge 3 + +The `source` function can be used to use a script within a script. +Assume you would like to load the same type of file over and over +again and therefore you need to specify the arguments to fit the +needs of your file. Instead of writing the necessary argument again +and again you could just write it once and save it as a script. Then, +you can use `source("Your_Script_containing_the_load_function")` in a new +script to use the function of that script without writing everything again. +Check out `?source` to find out more. + + +``` r +download.file("https://raw.githubusercontent.com/swcarpentry/r-novice-gapminder/main/episodes/data/gapminder_data.csv", destfile = "data/gapminder_data.csv") +gapminder <- read.csv(file = "data/gapminder_data.csv") +``` + +To run the script and load the data into the `gapminder` variable: + + +``` r +source(file = "scripts/load-gapminder.R") +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +Read the output of `str(gapminder)` again; +this time, use what you've learned about lists and vectors, +as well as the output of functions like `colnames` and `dim` +to explain what everything that `str` prints out for gapminder means. +If there are any parts you can't interpret, discuss with your neighbors! + +::::::::::::::: solution + +## Solution to Challenge 4 + +The object `gapminder` is a data frame with columns + +- `country` and `continent` are character strings. +- `year` is an integer vector. +- `pop`, `lifeExp`, and `gdpPercap` are numeric vectors. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `cbind()` to add a new column to a data frame. +- Use `rbind()` to add a new row to a data frame. +- Remove rows from a data frame. +- Use `str()`, `summary()`, `nrow()`, `ncol()`, `dim()`, `colnames()`, `head()`, and `typeof()` to understand the structure of a data frame. +- Read in a csv file using `read.csv()`. +- Understand what `length()` of a data frame represents. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/06-data-subsetting.md b/06-data-subsetting.md new file mode 100644 index 000000000..37ce85487 --- /dev/null +++ b/06-data-subsetting.md @@ -0,0 +1,1285 @@ +--- +title: Subsetting Data +teaching: 35 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To be able to subset vectors, factors, matrices, lists, and data frames +- To be able to extract individual and multiple elements: by index, by name, using comparison operations +- To be able to skip and remove elements from various data structures. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I work with subsets of data in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +R has many powerful subset operators. Mastering them will allow you to +easily perform complex operations on any kind of dataset. + +There are six different ways we can subset any kind of object, and three +different subsetting operators for the different data structures. + +Let's start with the workhorse of R: a simple numeric vector. + + +``` r +x <- c(5.4, 6.2, 7.1, 4.8, 7.5) +names(x) <- c('a', 'b', 'c', 'd', 'e') +x +``` + +``` output + a b c d e +5.4 6.2 7.1 4.8 7.5 +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Atomic vectors + +In R, simple vectors containing character strings, numbers, or logical values are called *atomic* vectors because they can't be further simplified. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +So now that we've created a dummy vector to play with, how do we get at its +contents? + +## Accessing elements using their indices + +To extract elements of a vector we can give their corresponding index, starting +from one: + + +``` r +x[1] +``` + +``` output + a +5.4 +``` + + +``` r +x[4] +``` + +``` output + d +4.8 +``` + +It may look different, but the square brackets operator is a function. For vectors +(and matrices), it means "get me the nth element". + +We can ask for multiple elements at once: + + +``` r +x[c(1, 3)] +``` + +``` output + a c +5.4 7.1 +``` + +Or slices of the vector: + + +``` r +x[1:4] +``` + +``` output + a b c d +5.4 6.2 7.1 4.8 +``` + +the `:` operator creates a sequence of numbers from the left element to the right. + + +``` r +1:4 +``` + +``` output +[1] 1 2 3 4 +``` + +``` r +c(1, 2, 3, 4) +``` + +``` output +[1] 1 2 3 4 +``` + +We can ask for the same element multiple times: + + +``` r +x[c(1,1,3)] +``` + +``` output + a a c +5.4 5.4 7.1 +``` + +If we ask for an index beyond the length of the vector, R will return a missing value: + + +``` r +x[6] +``` + +``` output + + NA +``` + +This is a vector of length one containing an `NA`, whose name is also `NA`. + +If we ask for the 0th element, we get an empty vector: + + +``` r +x[0] +``` + +``` output +named numeric(0) +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Vector numbering in R starts at 1 + +In many programming languages (C and Python, for example), the first +element of a vector has an index of 0. In R, the first element is 1. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Skipping and removing elements + +If we use a negative number as the index of a vector, R will return +every element *except* for the one specified: + + +``` r +x[-2] +``` + +``` output + a c d e +5.4 7.1 4.8 7.5 +``` + +We can skip multiple elements: + + +``` r +x[c(-1, -5)] # or x[-c(1,5)] +``` + +``` output + b c d +6.2 7.1 4.8 +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Order of operations + +A common trip up for novices occurs when trying to skip +slices of a vector. It's natural to try to negate a +sequence like so: + + +``` r +x[-1:3] +``` + +This gives a somewhat cryptic error: + + +``` error +Error in x[-1:3]: only 0's may be mixed with negative subscripts +``` + +But remember the order of operations. `:` is really a function. +It takes its first argument as -1, and its second as 3, +so generates the sequence of numbers: `c(-1, 0, 1, 2, 3)`. + +The correct solution is to wrap that function call in brackets, so +that the `-` operator applies to the result: + + +``` r +x[-(1:3)] +``` + +``` output + d e +4.8 7.5 +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +To remove elements from a vector, we need to assign the result back +into the variable: + + +``` r +x <- x[-4] +x +``` + +``` output + a b c e +5.4 6.2 7.1 7.5 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Given the following code: + + +``` r +x <- c(5.4, 6.2, 7.1, 4.8, 7.5) +names(x) <- c('a', 'b', 'c', 'd', 'e') +print(x) +``` + +``` output + a b c d e +5.4 6.2 7.1 4.8 7.5 +``` + +Come up with at least 2 different commands that will produce the following output: + + +``` output + b c d +6.2 7.1 4.8 +``` + +After you find 2 different commands, compare notes with your neighbour. Did you have different strategies? + +::::::::::::::: solution + +## Solution to challenge 1 + + +``` r +x[2:4] +``` + +``` output + b c d +6.2 7.1 4.8 +``` + + +``` r +x[-c(1,5)] +``` + +``` output + b c d +6.2 7.1 4.8 +``` + + +``` r +x[c(2,3,4)] +``` + +``` output + b c d +6.2 7.1 4.8 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Subsetting by name + +We can extract elements by using their name, instead of extracting by index: + + +``` r +x <- c(a=5.4, b=6.2, c=7.1, d=4.8, e=7.5) # we can name a vector 'on the fly' +x[c("a", "c")] +``` + +``` output + a c +5.4 7.1 +``` + +This is usually a much more reliable way to subset objects: the +position of various elements can often change when chaining together +subsetting operations, but the names will always remain the same! + +## Subsetting through other logical operations {#logical-operations} + +We can also use any logical vector to subset: + + +``` r +x[c(FALSE, FALSE, TRUE, FALSE, TRUE)] +``` + +``` output + c e +7.1 7.5 +``` + +Since comparison operators (e.g. `>`, `<`, `==`) evaluate to logical vectors, we can also +use them to succinctly subset vectors: the following statement gives +the same result as the previous one. + + +``` r +x[x > 7] +``` + +``` output + c e +7.1 7.5 +``` + +Breaking it down, this statement first evaluates `x>7`, generating +a logical vector `c(FALSE, FALSE, TRUE, FALSE, TRUE)`, and then +selects the elements of `x` corresponding to the `TRUE` values. + +We can use `==` to mimic the previous method of indexing by name +(remember you have to use `==` rather than `=` for comparisons): + + +``` r +x[names(x) == "a"] +``` + +``` output + a +5.4 +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Combining logical conditions + +We often want to combine multiple logical +criteria. For example, we might want to find all the countries that are +located in Asia **or** Europe **and** have life expectancies within a certain +range. Several operations for combining logical vectors exist in R: + +- `&`, the "logical AND" operator: returns `TRUE` if both the left and right + are `TRUE`. +- `|`, the "logical OR" operator: returns `TRUE`, if either the left or right + (or both) are `TRUE`. + +You may sometimes see `&&` and `||` instead of `&` and `|`. These two-character operators +only look at the first element of each vector and ignore the +remaining elements. In general you should not use the two-character +operators in data analysis; save them +for programming, i.e. deciding whether to execute a statement. + +- `!`, the "logical NOT" operator: converts `TRUE` to `FALSE` and `FALSE` to + `TRUE`. It can negate a single logical condition (eg `!TRUE` becomes + `FALSE`), or a whole vector of conditions(eg `!c(TRUE, FALSE)` becomes + `c(FALSE, TRUE)`). + +Additionally, you can compare the elements within a single vector using the +`all` function (which returns `TRUE` if every element of the vector is `TRUE`) +and the `any` function (which returns `TRUE` if one or more elements of the +vector are `TRUE`). + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Given the following code: + + +``` r +x <- c(5.4, 6.2, 7.1, 4.8, 7.5) +names(x) <- c('a', 'b', 'c', 'd', 'e') +print(x) +``` + +``` output + a b c d e +5.4 6.2 7.1 4.8 7.5 +``` + +Write a subsetting command to return the values in x that are greater than 4 and less than 7. + +::::::::::::::: solution + +## Solution to challenge 2 + + +``` r +x_subset <- x[x<7 & x>4] +print(x_subset) +``` + +``` output + a b d +5.4 6.2 4.8 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Non-unique names + +You should be aware that it is possible for multiple elements in a +vector to have the same name. (For a data frame, columns can have +the same name --- although R tries to avoid this --- but row names +must be unique.) Consider these examples: + + +``` r +x <- 1:3 +x +``` + +``` output +[1] 1 2 3 +``` + +``` r +names(x) <- c('a', 'a', 'a') +x +``` + +``` output +a a a +1 2 3 +``` + +``` r +x['a'] # only returns first value +``` + +``` output +a +1 +``` + +``` r +x[names(x) == 'a'] # returns all three values +``` + +``` output +a a a +1 2 3 +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Getting help for operators + +Remember you can search for help on operators by wrapping them in quotes: +`help("%in%")` or `?"%in%"`. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Skipping named elements + +Skipping or removing named elements is a little harder. If we try to skip one named element by negating the string, R complains (slightly obscurely) that it doesn't know how to take the negative of a string: + + +``` r +x <- c(a=5.4, b=6.2, c=7.1, d=4.8, e=7.5) # we start again by naming a vector 'on the fly' +x[-"a"] +``` + +``` error +Error in -"a": invalid argument to unary operator +``` + +However, we can use the `!=` (not-equals) operator to construct a logical vector that will do what we want: + + +``` r +x[names(x) != "a"] +``` + +``` output + b c d e +6.2 7.1 4.8 7.5 +``` + +Skipping multiple named indices is a little bit harder still. Suppose we want to drop the `"a"` and `"c"` elements, so we try this: + + +``` r +x[names(x)!=c("a","c")] +``` + +``` warning +Warning in names(x) != c("a", "c"): longer object length is not a multiple of +shorter object length +``` + +``` output + b c d e +6.2 7.1 4.8 7.5 +``` + +R did *something*, but it gave us a warning that we ought to pay attention to - and it apparently *gave us the wrong answer* (the `"c"` element is still included in the vector)! + +So what does `!=` actually do in this case? That's an excellent question. + +### Recycling + +Let's take a look at the comparison component of this code: + + +``` r +names(x) != c("a", "c") +``` + +``` warning +Warning in names(x) != c("a", "c"): longer object length is not a multiple of +shorter object length +``` + +``` output +[1] FALSE TRUE TRUE TRUE TRUE +``` + +Why does R give `TRUE` as the third element of this vector, when `names(x)[3] != "c"` is obviously false? +When you use `!=`, R tries to compare each element +of the left argument with the corresponding element of its right +argument. What happens when you compare vectors of different lengths? + +![](fig/06-rmd-inequality.1.png){alt='Inequality testing'} + +When one vector is shorter than the other, it gets *recycled*: + +![](fig/06-rmd-inequality.2.png){alt='Inequality testing: results of recycling'} + +In this case R **repeats** `c("a", "c")` as many times as necessary to match `names(x)`, i.e. we get `c("a","c","a","c","a")`. Since the recycled `"a"` +doesn't match the third element of `names(x)`, the value of `!=` is `TRUE`. +Because in this case the longer vector length (5) isn't a multiple of the shorter vector length (2), R printed a warning message. If we had been unlucky and `names(x)` had contained six elements, R would *silently* have done the wrong thing (i.e., not what we intended it to do). This recycling rule can can introduce hard-to-find and subtle bugs! + +The way to get R to do what we really want (match *each* element of the left argument with *all* of the elements of the right argument) it to use the `%in%` operator. The `%in%` operator goes through each element of its left argument, in this case the names of `x`, and asks, "Does this element occur in the second argument?". Here, since we want to *exclude* values, we also need a `!` operator to change "in" to "not in": + + +``` r +x[! names(x) %in% c("a","c") ] +``` + +``` output + b d e +6.2 4.8 7.5 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Selecting elements of a vector that match any of a list of components +is a very common data analysis task. For example, the gapminder data set +contains `country` and `continent` variables, but no information between +these two scales. Suppose we want to pull out information from southeast +Asia: how do we set up an operation to produce a logical vector that +is `TRUE` for all of the countries in southeast Asia and `FALSE` otherwise? + +Suppose you have these data: + + +``` r +seAsia <- c("Myanmar","Thailand","Cambodia","Vietnam","Laos") +## read in the gapminder data that we downloaded in episode 2 +gapminder <- read.csv("data/gapminder_data.csv", header=TRUE) +## extract the `country` column from a data frame (we'll see this later); +## convert from a factor to a character; +## and get just the non-repeated elements +countries <- unique(as.character(gapminder$country)) +``` + +There's a wrong way (using only `==`), which will give you a warning; +a clunky way (using the logical operators `==` and `|`); and +an elegant way (using `%in%`). See whether you can come up with all three +and explain how they (don't) work. + +::::::::::::::: solution + +## Solution to challenge 3 + +- The **wrong** way to do this problem is `countries==seAsia`. This + gives a warning (`"In countries == seAsia : longer object length is not a multiple of shorter object length"`) and the wrong answer (a vector of all + `FALSE` values), because none of the recycled values of `seAsia` happen + to line up correctly with matching values in `country`. +- The **clunky** (but technically correct) way to do this problem is + + +``` r + (countries=="Myanmar" | countries=="Thailand" | + countries=="Cambodia" | countries == "Vietnam" | countries=="Laos") +``` + +(or `countries==seAsia[1] | countries==seAsia[2] | ...`). This +gives the correct values, but hopefully you can see how awkward it +is (what if we wanted to select countries from a much longer list?). + +- The best way to do this problem is `countries %in% seAsia`, which + is both correct and easy to type (and read). + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Handling special values + +At some point you will encounter functions in R that cannot handle missing, infinite, +or undefined data. + +There are a number of special functions you can use to filter out this data: + +- `is.na` will return all positions in a vector, matrix, or data.frame + containing `NA` (or `NaN`) +- likewise, `is.nan`, and `is.infinite` will do the same for `NaN` and `Inf`. +- `is.finite` will return all positions in a vector, matrix, or data.frame + that do not contain `NA`, `NaN` or `Inf`. +- `na.omit` will filter out all missing values from a vector + +## Factor subsetting + +Now that we've explored the different ways to subset vectors, how +do we subset the other data structures? + +Factor subsetting works the same way as vector subsetting. + + +``` r +f <- factor(c("a", "a", "b", "c", "c", "d")) +f[f == "a"] +``` + +``` output +[1] a a +Levels: a b c d +``` + +``` r +f[f %in% c("b", "c")] +``` + +``` output +[1] b c c +Levels: a b c d +``` + +``` r +f[1:3] +``` + +``` output +[1] a a b +Levels: a b c d +``` + +Skipping elements will not remove the level +even if no more of that category exists in the factor: + + +``` r +f[-3] +``` + +``` output +[1] a a c c d +Levels: a b c d +``` + +## Matrix subsetting + +Matrices are also subsetted using the `[` function. In this case +it takes two arguments: the first applying to the rows, the second +to its columns: + + +``` r +set.seed(1) +m <- matrix(rnorm(6*4), ncol=4, nrow=6) +m[3:4, c(3,1)] +``` + +``` output + [,1] [,2] +[1,] 1.12493092 -0.8356286 +[2,] -0.04493361 1.5952808 +``` + +You can leave the first or second arguments blank to retrieve all the +rows or columns respectively: + + +``` r +m[, c(3,4)] +``` + +``` output + [,1] [,2] +[1,] -0.62124058 0.82122120 +[2,] -2.21469989 0.59390132 +[3,] 1.12493092 0.91897737 +[4,] -0.04493361 0.78213630 +[5,] -0.01619026 0.07456498 +[6,] 0.94383621 -1.98935170 +``` + +If we only access one row or column, R will automatically convert the result +to a vector: + + +``` r +m[3,] +``` + +``` output +[1] -0.8356286 0.5757814 1.1249309 0.9189774 +``` + +If you want to keep the output as a matrix, you need to specify a *third* argument; +`drop = FALSE`: + + +``` r +m[3, , drop=FALSE] +``` + +``` output + [,1] [,2] [,3] [,4] +[1,] -0.8356286 0.5757814 1.124931 0.9189774 +``` + +Unlike vectors, if we try to access a row or column outside of the matrix, +R will throw an error: + + +``` r +m[, c(3,6)] +``` + +``` error +Error in m[, c(3, 6)]: subscript out of bounds +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Higher dimensional arrays + +when dealing with multi-dimensional arrays, each argument to `[` +corresponds to a dimension. For example, a 3D array, the first three +arguments correspond to the rows, columns, and depth dimension. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Because matrices are vectors, we can +also subset using only one argument: + + +``` r +m[5] +``` + +``` output +[1] 0.3295078 +``` + +This usually isn't useful, and often confusing to read. However it is useful to note that matrices +are laid out in *column-major format* by default. That is the elements of the +vector are arranged column-wise: + + +``` r +matrix(1:6, nrow=2, ncol=3) +``` + +``` output + [,1] [,2] [,3] +[1,] 1 3 5 +[2,] 2 4 6 +``` + +If you wish to populate the matrix by row, use `byrow=TRUE`: + + +``` r +matrix(1:6, nrow=2, ncol=3, byrow=TRUE) +``` + +``` output + [,1] [,2] [,3] +[1,] 1 2 3 +[2,] 4 5 6 +``` + +Matrices can also be subsetted using their rownames and column names +instead of their row and column indices. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +Given the following code: + + +``` r +m <- matrix(1:18, nrow=3, ncol=6) +print(m) +``` + +``` output + [,1] [,2] [,3] [,4] [,5] [,6] +[1,] 1 4 7 10 13 16 +[2,] 2 5 8 11 14 17 +[3,] 3 6 9 12 15 18 +``` + +1. Which of the following commands will extract the values 11 and 14? + +A. `m[2,4,2,5]` + +B. `m[2:5]` + +C. `m[4:5,2]` + +D. `m[2,c(4,5)]` + +::::::::::::::: solution + +## Solution to challenge 4 + +D + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## List subsetting + +Now we'll introduce some new subsetting operators. There are three functions +used to subset lists. We've already seen these when learning about atomic vectors and matrices: `[`, `[[`, and `$`. + +Using `[` will always return a list. If you want to *subset* a list, but not +*extract* an element, then you will likely use `[`. + + +``` r +xlist <- list(a = "Software Carpentry", b = 1:10, data = head(mtcars)) +xlist[1] +``` + +``` output +$a +[1] "Software Carpentry" +``` + +This returns a *list with one element*. + +We can subset elements of a list exactly the same way as atomic +vectors using `[`. Comparison operations however won't work as +they're not recursive, they will try to condition on the data structures +in each element of the list, not the individual elements within those +data structures. + + +``` r +xlist[1:2] +``` + +``` output +$a +[1] "Software Carpentry" + +$b + [1] 1 2 3 4 5 6 7 8 9 10 +``` + +To extract individual elements of a list, you need to use the double-square +bracket function: `[[`. + + +``` r +xlist[[1]] +``` + +``` output +[1] "Software Carpentry" +``` + +Notice that now the result is a vector, not a list. + +You can't extract more than one element at once: + + +``` r +xlist[[1:2]] +``` + +``` error +Error in xlist[[1:2]]: subscript out of bounds +``` + +Nor use it to skip elements: + + +``` r +xlist[[-1]] +``` + +``` error +Error in xlist[[-1]]: invalid negative subscript in get1index +``` + +But you can use names to both subset and extract elements: + + +``` r +xlist[["a"]] +``` + +``` output +[1] "Software Carpentry" +``` + +The `$` function is a shorthand way for extracting elements by name: + + +``` r +xlist$data +``` + +``` output + mpg cyl disp hp drat wt qsec vs am gear carb +Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 +Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 +Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 +Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 +Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 +Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 5 + +Given the following list: + + +``` r +xlist <- list(a = "Software Carpentry", b = 1:10, data = head(mtcars)) +``` + +Using your knowledge of both list and vector subsetting, extract the number 2 from xlist. +Hint: the number 2 is contained within the "b" item in the list. + +::::::::::::::: solution + +## Solution to challenge 5 + + +``` r +xlist$b[2] +``` + +``` output +[1] 2 +``` + + +``` r +xlist[[2]][2] +``` + +``` output +[1] 2 +``` + + +``` r +xlist[["b"]][2] +``` + +``` output +[1] 2 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 6 + +Given a linear model: + + +``` r +mod <- aov(pop ~ lifeExp, data=gapminder) +``` + +Extract the residual degrees of freedom (hint: `attributes()` will help you) + +::::::::::::::: solution + +## Solution to challenge 6 + + +``` r +attributes(mod) ## `df.residual` is one of the names of `mod` +``` + + +``` r +mod$df.residual +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Data frames + +Remember the data frames are lists underneath the hood, so similar rules +apply. However they are also two dimensional objects: + +`[` with one argument will act the same way as for lists, where each list +element corresponds to a column. The resulting object will be a data frame: + + +``` r +head(gapminder[3]) +``` + +``` output + pop +1 8425333 +2 9240934 +3 10267083 +4 11537966 +5 13079460 +6 14880372 +``` + +Similarly, `[[` will act to extract *a single column*: + + +``` r +head(gapminder[["lifeExp"]]) +``` + +``` output +[1] 28.801 30.332 31.997 34.020 36.088 38.438 +``` + +And `$` provides a convenient shorthand to extract columns by name: + + +``` r +head(gapminder$year) +``` + +``` output +[1] 1952 1957 1962 1967 1972 1977 +``` + +With two arguments, `[` behaves the same way as for matrices: + + +``` r +gapminder[1:3,] +``` + +``` output + country year pop continent lifeExp gdpPercap +1 Afghanistan 1952 8425333 Asia 28.801 779.4453 +2 Afghanistan 1957 9240934 Asia 30.332 820.8530 +3 Afghanistan 1962 10267083 Asia 31.997 853.1007 +``` + +If we subset a single row, the result will be a data frame (because +the elements are mixed types): + + +``` r +gapminder[3,] +``` + +``` output + country year pop continent lifeExp gdpPercap +3 Afghanistan 1962 10267083 Asia 31.997 853.1007 +``` + +But for a single column the result will be a vector (this can +be changed with the third argument, `drop = FALSE`). + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 7 + +Fix each of the following common data frame subsetting errors: + +1. Extract observations collected for the year 1957 + + + ``` r + gapminder[gapminder$year = 1957,] + ``` + +2. Extract all columns except 1 through to 4 + + + ``` r + gapminder[,-1:4] + ``` + +3. Extract the rows where the life expectancy is longer the 80 years + + + ``` r + gapminder[gapminder$lifeExp > 80] + ``` + +4. Extract the first row, and the fourth and fifth columns + (`continent` and `lifeExp`). + + + ``` r + gapminder[1, 4, 5] + ``` + +5. Advanced: extract rows that contain information for the years 2002 + and 2007 + + + ``` r + gapminder[gapminder$year == 2002 | 2007,] + ``` + +::::::::::::::: solution + +## Solution to challenge 7 + +Fix each of the following common data frame subsetting errors: + +1. Extract observations collected for the year 1957 + + + ``` r + # gapminder[gapminder$year = 1957,] + gapminder[gapminder$year == 1957,] + ``` + +2. Extract all columns except 1 through to 4 + + + ``` r + # gapminder[,-1:4] + gapminder[,-c(1:4)] + ``` + +3. Extract the rows where the life expectancy is longer than 80 years + + + ``` r + # gapminder[gapminder$lifeExp > 80] + gapminder[gapminder$lifeExp > 80,] + ``` + +4. Extract the first row, and the fourth and fifth columns + (`continent` and `lifeExp`). + + + ``` r + # gapminder[1, 4, 5] + gapminder[1, c(4, 5)] + ``` + +5. Advanced: extract rows that contain information for the years 2002 + and 2007 + + + ``` r + # gapminder[gapminder$year == 2002 | 2007,] + gapminder[gapminder$year == 2002 | gapminder$year == 2007,] + gapminder[gapminder$year %in% c(2002, 2007),] + ``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 8 + +1. Why does `gapminder[1:20]` return an error? How does it differ from `gapminder[1:20, ]`? + +2. Create a new `data.frame` called `gapminder_small` that only contains rows 1 through 9 + and 19 through 23. You can do this in one or two steps. + +::::::::::::::: solution + +## Solution to challenge 8 + +1. `gapminder` is a data.frame so needs to be subsetted on two dimensions. `gapminder[1:20, ]` subsets the data to give the first 20 rows and all columns. + +2. + +``` r +gapminder_small <- gapminder[c(1:9, 19:23),] +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Indexing in R starts at 1, not 0. +- Access individual values by location using `[]`. +- Access slices of data using `[low:high]`. +- Access arbitrary sets of data using `[c(...)]`. +- Use logical operations and logical vectors to access subsets of data. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/07-control-flow.md b/07-control-flow.md new file mode 100644 index 000000000..fd43a75ef --- /dev/null +++ b/07-control-flow.md @@ -0,0 +1,675 @@ +--- +title: Control Flow +teaching: 45 +exercises: 20 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Write conditional statements with `if...else` statements and `ifelse()`. +- Write and understand `for()` loops. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I make data-dependent choices in R? +- How can I repeat operations in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +Often when we're coding we want to control the flow of our actions. This can be done +by setting actions to occur only if a condition or a set of conditions are met. +Alternatively, we can also set an action to occur a particular number of times. + +There are several ways you can control flow in R. +For conditional statements, the most commonly used approaches are the constructs: + + +``` r +# if +if (condition is true) { + perform action +} + +# if ... else +if (condition is true) { + perform action +} else { # that is, if the condition is false, + perform alternative action +} +``` + +Say, for example, that we want R to print a message if a variable `x` has a particular value: + + +``` r +x <- 8 + +if (x >= 10) { + print("x is greater than or equal to 10") +} + +x +``` + +``` output +[1] 8 +``` + +The print statement does not appear in the console because x is not greater than 10. To print a different message for numbers less than 10, we can add an `else` statement. + + +``` r +x <- 8 + +if (x >= 10) { + print("x is greater than or equal to 10") +} else { + print("x is less than 10") +} +``` + +``` output +[1] "x is less than 10" +``` + +You can also test multiple conditions by using `else if`. + + +``` r +x <- 8 + +if (x >= 10) { + print("x is greater than or equal to 10") +} else if (x > 5) { + print("x is greater than 5, but less than 10") +} else { + print("x is less than 5") +} +``` + +``` output +[1] "x is greater than 5, but less than 10" +``` + +**Important:** when R evaluates the condition inside `if()` statements, it is +looking for a logical element, i.e., `TRUE` or `FALSE`. This can cause some +headaches for beginners. For example: + + +``` r +x <- 4 == 3 +if (x) { + "4 equals 3" +} else { + "4 does not equal 3" +} +``` + +``` output +[1] "4 does not equal 3" +``` + +As we can see, the not equal message was printed because the vector x is `FALSE` + + +``` r +x <- 4 == 3 +x +``` + +``` output +[1] FALSE +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Use an `if()` statement to print a suitable message +reporting whether there are any records from 2002 in +the `gapminder` dataset. +Now do the same for 2012. + +::::::::::::::: solution + +## Solution to Challenge 1 + +We will first see a solution to Challenge 1 which does not use the `any()` function. +We first obtain a logical vector describing which element of `gapminder$year` is equal to `2002`: + + +``` r +gapminder[(gapminder$year == 2002),] +``` + +Then, we count the number of rows of the data.frame `gapminder` that correspond to the 2002: + + +``` r +rows2002_number <- nrow(gapminder[(gapminder$year == 2002),]) +``` + +The presence of any record for the year 2002 is equivalent to the request that `rows2002_number` is one or more: + + +``` r +rows2002_number >= 1 +``` + +Putting all together, we obtain: + + +``` r +if(nrow(gapminder[(gapminder$year == 2002),]) >= 1){ + print("Record(s) for the year 2002 found.") +} +``` + +All this can be done more quickly with `any()`. The logical condition can be expressed as: + + +``` r +if(any(gapminder$year == 2002)){ + print("Record(s) for the year 2002 found.") +} +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Did anyone get a warning message like this? + + +``` error +Error in if (gapminder$year == 2012) {: the condition has length > 1 +``` + +The `if()` function only accepts singular (of length 1) inputs, and therefore +returns an error when you use it with a vector. The `if()` function will still +run, but will only evaluate the condition in the first element of the vector. +Therefore, to use the `if()` function, you need to make sure your input is +singular (of length 1). + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Built in `ifelse()` function + +`R` accepts both `if()` and `else if()` statements structured as outlined above, +but also statements using `R`'s built-in `ifelse()` function. This +function accepts both singular and vector inputs and is structured as +follows: + + +``` r +# ifelse function +ifelse(condition is true, perform action, perform alternative action) +``` + +where the first argument is the condition or a set of conditions to be met, the +second argument is the statement that is evaluated when the condition is `TRUE`, +and the third statement is the statement that is evaluated when the condition +is `FALSE`. + + +``` r +y <- -3 +ifelse(y < 0, "y is a negative number", "y is either positive or zero") +``` + +``` output +[1] "y is a negative number" +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: `any()` and `all()` + +The `any()` function will return `TRUE` if at least one +`TRUE` value is found within a vector, otherwise it will return `FALSE`. +This can be used in a similar way to the `%in%` operator. +The function `all()`, as the name suggests, will only return `TRUE` if all values in +the vector are `TRUE`. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Repeating operations + +If you want to iterate over +a set of values, when the order of iteration is important, and perform the +same operation on each, a `for()` loop will do the job. +We saw `for()` loops in the [shell lessons earlier](https://swcarpentry.github.io/shell-novice/05-loop.html). This is the most +flexible of looping operations, but therefore also the hardest to use +correctly. In general, the advice of many `R` users would be to learn about +`for()` loops, but to avoid using `for()` loops unless the order of iteration is +important: i.e. the calculation at each iteration depends on the results of +previous iterations. If the order of iteration is not important, then you +should learn about vectorized alternatives, such as the `purrr` package, as they +pay off in computational efficiency. + +The basic structure of a `for()` loop is: + + +``` r +for (iterator in set of values) { + do a thing +} +``` + +For example: + + +``` r +for (i in 1:10) { + print(i) +} +``` + +``` output +[1] 1 +[1] 2 +[1] 3 +[1] 4 +[1] 5 +[1] 6 +[1] 7 +[1] 8 +[1] 9 +[1] 10 +``` + +The `1:10` bit creates a vector on the fly; you can iterate +over any other vector as well. + +We can use a `for()` loop nested within another `for()` loop to iterate over two things at +once. + + +``` r +for (i in 1:5) { + for (j in c('a', 'b', 'c', 'd', 'e')) { + print(paste(i,j)) + } +} +``` + +``` output +[1] "1 a" +[1] "1 b" +[1] "1 c" +[1] "1 d" +[1] "1 e" +[1] "2 a" +[1] "2 b" +[1] "2 c" +[1] "2 d" +[1] "2 e" +[1] "3 a" +[1] "3 b" +[1] "3 c" +[1] "3 d" +[1] "3 e" +[1] "4 a" +[1] "4 b" +[1] "4 c" +[1] "4 d" +[1] "4 e" +[1] "5 a" +[1] "5 b" +[1] "5 c" +[1] "5 d" +[1] "5 e" +``` + +We notice in the output that when the first index (`i`) is set to 1, the second +index (`j`) iterates through its full set of indices. Once the indices of `j` +have been iterated through, then `i` is incremented. This process continues +until the last index has been used for each `for()` loop. + +Rather than printing the results, we could write the loop output to a new object. + + +``` r +output_vector <- c() +for (i in 1:5) { + for (j in c('a', 'b', 'c', 'd', 'e')) { + temp_output <- paste(i, j) + output_vector <- c(output_vector, temp_output) + } +} +output_vector +``` + +``` output + [1] "1 a" "1 b" "1 c" "1 d" "1 e" "2 a" "2 b" "2 c" "2 d" "2 e" "3 a" "3 b" +[13] "3 c" "3 d" "3 e" "4 a" "4 b" "4 c" "4 d" "4 e" "5 a" "5 b" "5 c" "5 d" +[25] "5 e" +``` + +This approach can be useful, but 'growing your results' (building +the result object incrementally) is computationally inefficient, so avoid +it when you are iterating through a lot of values. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: don't grow your results + +One of the biggest things that trips up novices and +experienced R users alike, is building a results object +(vector, list, matrix, data frame) as your for loop progresses. +Computers are very bad at handling this, so your calculations +can very quickly slow to a crawl. It's much better to define +an empty results object before hand of appropriate dimensions, rather +than initializing an empty object without dimensions. +So if you know the end result will be stored in a matrix like above, +create an empty matrix with 5 row and 5 columns, then at each iteration +store the results in the appropriate location. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +A better way is to define your (empty) output object before filling in the values. +For this example, it looks more involved, but is still more efficient. + + +``` r +output_matrix <- matrix(nrow = 5, ncol = 5) +j_vector <- c('a', 'b', 'c', 'd', 'e') +for (i in 1:5) { + for (j in 1:5) { + temp_j_value <- j_vector[j] + temp_output <- paste(i, temp_j_value) + output_matrix[i, j] <- temp_output + } +} +output_vector2 <- as.vector(output_matrix) +output_vector2 +``` + +``` output + [1] "1 a" "2 a" "3 a" "4 a" "5 a" "1 b" "2 b" "3 b" "4 b" "5 b" "1 c" "2 c" +[13] "3 c" "4 c" "5 c" "1 d" "2 d" "3 d" "4 d" "5 d" "1 e" "2 e" "3 e" "4 e" +[25] "5 e" +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: While loops + +Sometimes you will find yourself needing to repeat an operation as long as a certain +condition is met. You can do this with a `while()` loop. + + +``` r +while(this condition is true){ + do a thing +} +``` + +R will interpret a condition being met as "TRUE". + +As an example, here's a while loop +that generates random numbers from a uniform distribution (the `runif()` function) +between 0 and 1 until it gets one that's less than 0.1. + +```r +z <- 1 +while(z > 0.1){ + z <- runif(1) + cat(z, "\n") +} +``` + +`while()` loops will not always be appropriate. You have to be particularly careful +that you don't end up stuck in an infinite loop because your condition is always met and hence the while statement never terminates. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Compare the objects `output_vector` and +`output_vector2`. Are they the same? If not, why not? +How would you change the last block of code to make `output_vector2` +the same as `output_vector`? + +::::::::::::::: solution + +## Solution to Challenge 2 + +We can check whether the two vectors are identical using the `all()` function: + + +``` r +all(output_vector == output_vector2) +``` + +However, all the elements of `output_vector` can be found in `output_vector2`: + + +``` r +all(output_vector %in% output_vector2) +``` + +and vice versa: + + +``` r +all(output_vector2 %in% output_vector) +``` + +therefore, the element in `output_vector` and `output_vector2` are just sorted in a different order. +This is because `as.vector()` outputs the elements of an input matrix going over its column. +Taking a look at `output_matrix`, we can notice that we want its elements by rows. +The solution is to transpose the `output_matrix`. We can do it either by calling the transpose function +`t()` or by inputting the elements in the right order. +The first solution requires to change the original + + +``` r +output_vector2 <- as.vector(output_matrix) +``` + +into + + +``` r +output_vector2 <- as.vector(t(output_matrix)) +``` + +The second solution requires to change + + +``` r +output_matrix[i, j] <- temp_output +``` + +into + + +``` r +output_matrix[j, i] <- temp_output +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Write a script that loops through the `gapminder` data by continent and prints out +whether the mean life expectancy is smaller or larger than 50 +years. + +::::::::::::::: solution + +## Solution to Challenge 3 + +**Step 1**: We want to make sure we can extract all the unique values of the continent vector + + +``` r +gapminder <- read.csv("data/gapminder_data.csv") +unique(gapminder$continent) +``` + +**Step 2**: We also need to loop over each of these continents and calculate the average life expectancy for each `subset` of data. +We can do that as follows: + +1. Loop over each of the unique values of 'continent' +2. For each value of continent, create a temporary variable storing that subset +3. Return the calculated life expectancy to the user by printing the output: + + +``` r +for (iContinent in unique(gapminder$continent)) { + tmp <- gapminder[gapminder$continent == iContinent, ] + cat(iContinent, mean(tmp$lifeExp, na.rm = TRUE), "\n") + rm(tmp) +} +``` + +**Step 3**: The exercise only wants the output printed if the average life expectancy is less than 50 or greater than 50. +So we need to add an `if()` condition before printing, which evaluates whether the calculated average life expectancy is above or below a threshold, and prints an output conditional on the result. +We need to amend (3) from above: + +3a. If the calculated life expectancy is less than some threshold (50 years), return the continent and a statement that life expectancy is less than threshold, otherwise return the continent and a statement that life expectancy is greater than threshold: + + +``` r +thresholdValue <- 50 + +for (iContinent in unique(gapminder$continent)) { + tmp <- mean(gapminder[gapminder$continent == iContinent, "lifeExp"]) + + if (tmp < thresholdValue){ + cat("Average Life Expectancy in", iContinent, "is less than", thresholdValue, "\n") + } else { + cat("Average Life Expectancy in", iContinent, "is greater than", thresholdValue, "\n") + } # end if else condition + rm(tmp) +} # end for loop +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +Modify the script from Challenge 3 to loop over each +country. This time print out whether the life expectancy is +smaller than 50, between 50 and 70, or greater than 70. + +::::::::::::::: solution + +## Solution to Challenge 4 + +We modify our solution to Challenge 3 by now adding two thresholds, `lowerThreshold` and `upperThreshold` and extending our if-else statements: + + +``` r + lowerThreshold <- 50 + upperThreshold <- 70 + +for (iCountry in unique(gapminder$country)) { + tmp <- mean(gapminder[gapminder$country == iCountry, "lifeExp"]) + + if(tmp < lowerThreshold) { + cat("Average Life Expectancy in", iCountry, "is less than", lowerThreshold, "\n") + } else if(tmp > lowerThreshold && tmp < upperThreshold) { + cat("Average Life Expectancy in", iCountry, "is between", lowerThreshold, "and", upperThreshold, "\n") + } else { + cat("Average Life Expectancy in", iCountry, "is greater than", upperThreshold, "\n") + } + rm(tmp) +} +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 5 - Advanced + +Write a script that loops over each country in the `gapminder` dataset, +tests whether the country starts with a 'B', and graphs life expectancy +against time as a line graph if the mean life expectancy is under 50 years. + +::::::::::::::: solution + +## Solution for Challenge 5 + +We will use the `grep()` command that was introduced in the [Unix Shell lesson](https://swcarpentry.github.io/shell-novice/07-find.html) +to find countries that start with "B." +Lets understand how to do this first. +Following from the Unix shell section we may be tempted to try the following + + +``` r +grep("^B", unique(gapminder$country)) +``` + +But when we evaluate this command it returns the indices of the factor variable `country` that start with "B." +To get the values, we must add the `value=TRUE` option to the `grep()` command: + + +``` r +grep("^B", unique(gapminder$country), value = TRUE) +``` + +We will now store these countries in a variable called candidateCountries, and then loop over each entry in the variable. +Inside the loop, we evaluate the average life expectancy for each country, and if the average life expectancy is less than 50 we use base-plot to plot the evolution of average life expectancy using `with()` and `subset()`: + + +``` r +thresholdValue <- 50 +candidateCountries <- grep("^B", unique(gapminder$country), value = TRUE) + +for (iCountry in candidateCountries) { + tmp <- mean(gapminder[gapminder$country == iCountry, "lifeExp"]) + + if (tmp < thresholdValue) { + cat("Average Life Expectancy in", iCountry, "is less than", thresholdValue, "plotting life expectancy graph... \n") + + with(subset(gapminder, country == iCountry), + plot(year, lifeExp, + type = "o", + main = paste("Life Expectancy in", iCountry, "over time"), + ylab = "Life Expectancy", + xlab = "Year" + ) # end plot + ) # end with + } # end if + rm(tmp) +} # end for loop +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `if` and `else` to make choices. +- Use `for` to repeat operations. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/08-plot-ggplot2.md b/08-plot-ggplot2.md new file mode 100644 index 000000000..b36eb75ff --- /dev/null +++ b/08-plot-ggplot2.md @@ -0,0 +1,555 @@ +--- +title: Creating Publication-Quality Graphics with ggplot2 +teaching: 60 +exercises: 20 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To be able to use ggplot2 to generate publication-quality graphics. +- To apply geometry, aesthetic, and statistics layers to a ggplot plot. +- To manipulate the aesthetics of a plot using different colors, shapes, and lines. +- To improve data visualization through transforming scales and paneling by group. +- To save a plot created with ggplot to disk. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I create publication-quality graphics in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +Plotting our data is one of the best ways to +quickly explore it and the various relationships +between variables. + +There are three main plotting systems in R, +the [base plotting system][base], the [lattice] +package, and the [ggplot2] package. + +Today we'll be learning about the ggplot2 package, because +it is the most effective for creating publication-quality +graphics. + +ggplot2 is built on the grammar of graphics, the idea that any plot can be +built from the same set of components: a **data set**, +**mapping aesthetics**, and graphical **layers**: + +- **Data sets** are the data that you, the user, provide. + +- **Mapping aesthetics** are what connect the data to the graphics. + They tell ggplot2 how to use your data to affect how the graph looks, + such as changing what is plotted on the X or Y axis, or the size or + color of different data points. + +- **Layers** are the actual graphical output from ggplot2. Layers + determine what kinds of plot are shown (scatterplot, histogram, etc.), + the coordinate system used (rectangular, polar, others), and other + important aspects of the plot. The idea of layers of graphics may + be familiar to you if you have used image editing programs + like Photoshop, Illustrator, or Inkscape. + +Let's start off building an example using the gapminder data from earlier. +The most basic function is `ggplot`, which lets R know that we're +creating a new plot. Any of the arguments we give the `ggplot` +function are the *global* options for the plot: they apply to all +layers on the plot. + + +``` r +library("ggplot2") +ggplot(data = gapminder) +``` + +Blank plot, before adding any mapping aesthetics to ggplot(). + +Here we called `ggplot` and told it what data we want to show on +our figure. This is not enough information for `ggplot` to actually +draw anything. It only creates a blank slate for other elements +to be added to. + +Now we're going to add in the **mapping aesthetics** using the +`aes` function. `aes` tells `ggplot` how variables in the **data** +map to *aesthetic* properties of the figure, such as which columns +of the data should be used for the **x** and **y** locations. + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) +``` + +Plotting area with axes for a scatter plot of life expectancy vs GDP, with no data points visible. + +Here we told `ggplot` we want to plot the "gdpPercap" column of the +gapminder data frame on the x-axis, and the "lifeExp" column on the +y-axis. Notice that we didn't need to explicitly pass `aes` these +columns (e.g. `x = gapminder[, "gdpPercap"]`), this is because +`ggplot` is smart enough to know to look in the **data** for that column! + +The final part of making our plot is to tell `ggplot` how we want to +visually represent the data. We do this by adding a new **layer** +to the plot using one of the **geom** functions. + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + + geom_point() +``` + +Scatter plot of life expectancy vs GDP per capita, now showing the data points. + +Here we used `geom_point`, which tells `ggplot` we want to visually +represent the relationship between **x** and **y** as a scatterplot of points. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Modify the example so that the figure shows how life expectancy has +changed over time: + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + geom_point() +``` + +Hint: the gapminder dataset has a column called "year", which should appear +on the x-axis. + +::::::::::::::: solution + +## Solution to challenge 1 + +Here is one possible solution: + + +``` r +ggplot(data = gapminder, mapping = aes(x = year, y = lifeExp)) + geom_point() +``` + +
+Binned scatterplot of life expectancy versus year showing how life expectancy has increased over time +

Binned scatterplot of life expectancy versus year showing how life expectancy has increased over time

+
+ +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +In the previous examples and challenge we've used the `aes` function to tell +the scatterplot **geom** about the **x** and **y** locations of each point. +Another *aesthetic* property we can modify is the point *color*. Modify the +code from the previous challenge to **color** the points by the "continent" +column. What trends do you see in the data? Are they what you expected? + +::::::::::::::: solution + +## Solution to challenge 2 + +The solution presented below adds `color=continent` to the call of the `aes` +function. The general trend seems to indicate an increased life expectancy +over the years. On continents with stronger economies we find a longer life +expectancy. + + +``` r +ggplot(data = gapminder, mapping = aes(x = year, y = lifeExp, color=continent)) + + geom_point() +``` + +
+Binned scatterplot of life expectancy vs year with color-coded continents showing value of 'aes' function +

Binned scatterplot of life expectancy vs year with color-coded continents showing value of 'aes' function

+
+ +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Layers + +Using a scatterplot probably isn't the best for visualizing change over time. +Instead, let's tell `ggplot` to visualize the data as a line plot: + + +``` r +ggplot(data = gapminder, mapping = aes(x=year, y=lifeExp, color=continent)) + + geom_line() +``` + + + +Instead of adding a `geom_point` layer, we've added a `geom_line` layer. + +However, the result doesn't look quite as we might have expected: it seems to be jumping around a lot in each continent. Let's try to separate the data by country, plotting one line for each country: + + +``` r +ggplot(data = gapminder, mapping = aes(x=year, y=lifeExp, group=country, color=continent)) + + geom_line() +``` + + + +We've added the **group** *aesthetic*, which tells `ggplot` to draw a line for each +country. + +But what if we want to visualize both lines and points on the plot? We can +add another layer to the plot: + + +``` r +ggplot(data = gapminder, mapping = aes(x=year, y=lifeExp, group=country, color=continent)) + + geom_line() + geom_point() +``` + + + +It's important to note that each layer is drawn on top of the previous layer. In +this example, the points have been drawn *on top of* the lines. Here's a +demonstration: + + +``` r +ggplot(data = gapminder, mapping = aes(x=year, y=lifeExp, group=country)) + + geom_line(mapping = aes(color=continent)) + geom_point() +``` + + + +In this example, the *aesthetic* mapping of **color** has been moved from the +global plot options in `ggplot` to the `geom_line` layer so it no longer applies +to the points. Now we can clearly see that the points are drawn on top of the +lines. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Setting an aesthetic to a value instead of a mapping + +So far, we've seen how to use an aesthetic (such as **color**) as a *mapping* to a variable in the data. For example, when we use `geom_line(mapping = aes(color=continent))`, ggplot will give a different color to each continent. But what if we want to change the color of all lines to blue? You may think that `geom_line(mapping = aes(color="blue"))` should work, but it doesn't. Since we don't want to create a mapping to a specific variable, we can move the color specification outside of the `aes()` function, like this: `geom_line(color="blue")`. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Switch the order of the point and line layers from the previous example. What +happened? + +::::::::::::::: solution + +## Solution to challenge 3 + +The lines now get drawn over the points! + + +``` r +ggplot(data = gapminder, mapping = aes(x=year, y=lifeExp, group=country)) + + geom_point() + geom_line(mapping = aes(color=continent)) +``` + +Scatter plot of life expectancy vs GDP per capita with a trend line summarising the relationship between variables. The plot illustrates the possibilities for styling visualisations in ggplot2 with data points enlarged, coloured orange, and displayed without transparency. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Transformations and statistics + +ggplot2 also makes it easy to overlay statistical models over the data. To +demonstrate we'll go back to our first example: + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + + geom_point() +``` + + + +Currently it's hard to see the relationship between the points due to some strong +outliers in GDP per capita. We can change the scale of units on the x axis using +the *scale* functions. These control the mapping between the data values and +visual values of an aesthetic. We can also modify the transparency of the +points, using the *alpha* function, which is especially helpful when you have +a large amount of data which is very clustered. + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + + geom_point(alpha = 0.5) + scale_x_log10() +``` + +
+Scatterplot of GDP vs life expectancy showing logarithmic x-axis data spread +

Scatterplot of GDP vs life expectancy showing logarithmic x-axis data spread

+
+ +The `scale_x_log10` function applied a transformation to the coordinate system of the plot, so that each multiple of 10 is evenly spaced from left to right. For example, a GDP per capita of 1,000 is the same horizontal distance away from a value of 10,000 as the 10,000 value is from 100,000. This helps to visualize the spread of the data along the x-axis. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip Reminder: Setting an aesthetic to a value instead of a mapping + +Notice that we used `geom_point(alpha = 0.5)`. As the previous tip mentioned, using a setting outside of the `aes()` function will cause this value to be used for all points, which is what we want in this case. But just like any other aesthetic setting, *alpha* can also be mapped to a variable in the data. For example, we can give a different transparency to each continent with `geom_point(mapping = aes(alpha = continent))`. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +We can fit a simple relationship to the data by adding another layer, +`geom_smooth`: + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + + geom_point(alpha = 0.5) + scale_x_log10() + geom_smooth(method="lm") +``` + +``` output +`geom_smooth()` using formula = 'y ~ x' +``` + +Scatter plot of life expectancy vs GDP per capita with a blue trend line summarising the relationship between variables, and gray shaded area indicating 95% confidence intervals for that trend line. + +We can make the line thicker by *setting* the **linewidth** aesthetic in the +`geom_smooth` layer: + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + + geom_point(alpha = 0.5) + scale_x_log10() + geom_smooth(method="lm", linewidth=1.5) +``` + +``` output +`geom_smooth()` using formula = 'y ~ x' +``` + +Scatter plot of life expectancy vs GDP per capita with a trend line summarising the relationship between variables. The blue trend line is slightly thicker than in the previous figure. + +There are two ways an *aesthetic* can be specified. Here we *set* the **linewidth** aesthetic by passing it as an argument to `geom_smooth` and it is applied the same to the whole `geom`. Previously in the lesson we've used the `aes` function to define a *mapping* between data variables and their visual representation. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4a + +Modify the color and size of the points on the point layer in the previous +example. + +Hint: do not use the `aes` function. + +Hint: the equivalent of `linewidth` for points is `size`. + +::::::::::::::: solution + +## Solution to challenge 4a + +Here a possible solution: +Notice that the `color` argument is supplied outside of the `aes()` function. +This means that it applies to all data points on the graph and is not related to +a specific variable. + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + + geom_point(size=3, color="orange") + scale_x_log10() + + geom_smooth(method="lm", linewidth=1.5) +``` + +``` output +`geom_smooth()` using formula = 'y ~ x' +``` + +Scatter plot of life expectancy vs GDP per capita with a trend line summarising the relationship between variables. The plot illustrates the possibilities for styling visualisations in ggplot2 with data points enlarged, coloured orange, and displayed without transparency. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4b + +Modify your solution to Challenge 4a so that the +points are now a different shape and are colored by continent with new +trendlines. Hint: The color argument can be used inside the aesthetic. + +::::::::::::::: solution + +## Solution to challenge 4b + +Here is a possible solution: +Notice that supplying the `color` argument inside the `aes()` functions enables you to +connect it to a certain variable. The `shape` argument, as you can see, modifies all +data points the same way (it is outside the `aes()` call) while the `color` argument which +is placed inside the `aes()` call modifies a point's color based on its continent value. + + +``` r +ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp, color = continent)) + + geom_point(size=3, shape=17) + scale_x_log10() + + geom_smooth(method="lm", linewidth=1.5) +``` + +``` output +`geom_smooth()` using formula = 'y ~ x' +``` + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Multi-panel figures + +Earlier we visualized the change in life expectancy over time across all +countries in one plot. Alternatively, we can split this out over multiple panels +by adding a layer of **facet** panels. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip + +We start by making a subset of data including only countries located +in the Americas. This includes 25 countries, which will begin to +clutter the figure. Note that we apply a "theme" definition to rotate +the x-axis labels to maintain readability. Nearly everything in +ggplot2 is customizable. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +``` r +americas <- gapminder[gapminder$continent == "Americas",] +ggplot(data = americas, mapping = aes(x = year, y = lifeExp)) + + geom_line() + + facet_wrap( ~ country) + + theme(axis.text.x = element_text(angle = 45)) +``` + + + +The `facet_wrap` layer took a "formula" as its argument, denoted by the tilde +(~). This tells R to draw a panel for each unique value in the country column +of the gapminder dataset. + +## Modifying text + +To clean this figure up for a publication we need to change some of the text +elements. The x-axis is too cluttered, and the y axis should read +"Life expectancy", rather than the column name in the data frame. + +We can do this by adding a couple of different layers. The **theme** layer +controls the axis text, and overall text size. Labels for the axes, plot +title and any legend can be set using the `labs` function. Legend titles +are set using the same names we used in the `aes` specification. Thus below +the color legend title is set using `color = "Continent"`, while the title +of a fill legend would be set using `fill = "MyTitle"`. + + +``` r +ggplot(data = americas, mapping = aes(x = year, y = lifeExp, color=continent)) + + geom_line() + facet_wrap( ~ country) + + labs( + x = "Year", # x axis title + y = "Life expectancy", # y axis title + title = "Figure 1", # main title of figure + color = "Continent" # title of legend + ) + + theme(axis.text.x = element_text(angle = 90, hjust = 1)) +``` + + + +## Exporting the plot + +The `ggsave()` function allows you to export a plot created with ggplot. You can specify the dimension and resolution of your plot by adjusting the appropriate arguments (`width`, `height` and `dpi`) to create high quality graphics for publication. In order to save the plot from above, we first assign it to a variable `lifeExp_plot`, then tell `ggsave` to save that plot in `png` format to a directory called `results`. (Make sure you have a `results/` folder in your working directory.) + + + + +``` r +lifeExp_plot <- ggplot(data = americas, mapping = aes(x = year, y = lifeExp, color=continent)) + + geom_line() + facet_wrap( ~ country) + + labs( + x = "Year", # x axis title + y = "Life expectancy", # y axis title + title = "Figure 1", # main title of figure + color = "Continent" # title of legend + ) + + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + +ggsave(filename = "results/lifeExp.png", plot = lifeExp_plot, width = 12, height = 10, dpi = 300, units = "cm") +``` + +There are two nice things about `ggsave`. First, it defaults to the last plot, so if you omit the `plot` argument it will automatically save the last plot you created with `ggplot`. Secondly, it tries to determine the format you want to save your plot in from the file extension you provide for the filename (for example `.png` or `.pdf`). If you need to, you can specify the format explicitly in the `device` argument. + +This is a taste of what you can do with ggplot2. RStudio provides a +really useful [cheat sheet][cheat] of the different layers available, and more +extensive documentation is available on the [ggplot2 website][ggplot-doc]. All RStudio cheat sheets are available from the [RStudio website][cheat_all]. +Finally, if you have no idea how to change something, a quick Google search will +usually send you to a relevant question and answer on Stack Overflow with reusable +code to modify! + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 5 + +Generate boxplots to compare life expectancy between the different continents during the available years. + +Advanced: + +- Rename y axis as Life Expectancy. +- Remove x axis labels. + +::::::::::::::: solution + +## Solution to Challenge 5 + +Here a possible solution: +`xlab()` and `ylab()` set labels for the x and y axes, respectively +The axis title, text and ticks are attributes of the theme and must be modified within a `theme()` call. + + +``` r +ggplot(data = gapminder, mapping = aes(x = continent, y = lifeExp, fill = continent)) + + geom_boxplot() + facet_wrap(~year) + + ylab("Life Expectancy") + + theme(axis.title.x=element_blank(), + axis.text.x = element_blank(), + axis.ticks.x = element_blank()) +``` + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +[base]: https://www.statmethods.net/graphs/index.html +[lattice]: https://www.statmethods.net/advgraphs/trellis.html +[ggplot2]: https://www.statmethods.net/advgraphs/ggplot2.html +[cheat]: https://www.rstudio.org/links/data_visualization_cheat_sheet +[cheat_all]: https://www.rstudio.com/resources/cheatsheets/ +[ggplot-doc]: https://ggplot2.tidyverse.org/reference/ + + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `ggplot2` to create plots. +- Think about graphics in layers: aesthetics, geometry, statistics, scale transformation, and grouping. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/09-vectorization.md b/09-vectorization.md new file mode 100644 index 000000000..308ddea97 --- /dev/null +++ b/09-vectorization.md @@ -0,0 +1,489 @@ +--- +title: Vectorization +teaching: 10 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To understand vectorized operations in R. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I operate on all the elements of a vector at once? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +Most of R's functions are vectorized, meaning that the function will +operate on all elements of a vector without needing to loop through +and act on each element one at a time. This makes writing code more +concise, easy to read, and less error prone. + + +``` r +x <- 1:4 +x * 2 +``` + +``` output +[1] 2 4 6 8 +``` + +The multiplication happened to each element of the vector. + +We can also add two vectors together: + + +``` r +y <- 6:9 +x + y +``` + +``` output +[1] 7 9 11 13 +``` + +Each element of `x` was added to its corresponding element of `y`: + + +``` r +x: 1 2 3 4 + + + + + +y: 6 7 8 9 +--------------- + 7 9 11 13 +``` + +Here is how we would add two vectors together using a for loop: + + +``` r +output_vector <- c() +for (i in 1:4) { + output_vector[i] <- x[i] + y[i] +} +output_vector +``` + +``` output +[1] 7 9 11 13 +``` + +Compare this to the output using vectorised operations. + + +``` r +sum_xy <- x + y +sum_xy +``` + +``` output +[1] 7 9 11 13 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Let's try this on the `pop` column of the `gapminder` dataset. + +Make a new column in the `gapminder` data frame that +contains population in units of millions of people. +Check the head or tail of the data frame to make sure +it worked. + +::::::::::::::: solution + +## Solution to challenge 1 + +Let's try this on the `pop` column of the `gapminder` dataset. + +Make a new column in the `gapminder` data frame that +contains population in units of millions of people. +Check the head or tail of the data frame to make sure +it worked. + + +``` r +gapminder$pop_millions <- gapminder$pop / 1e6 +head(gapminder) +``` + +``` output + country year pop continent lifeExp gdpPercap pop_millions +1 Afghanistan 1952 8425333 Asia 28.801 779.4453 8.425333 +2 Afghanistan 1957 9240934 Asia 30.332 820.8530 9.240934 +3 Afghanistan 1962 10267083 Asia 31.997 853.1007 10.267083 +4 Afghanistan 1967 11537966 Asia 34.020 836.1971 11.537966 +5 Afghanistan 1972 13079460 Asia 36.088 739.9811 13.079460 +6 Afghanistan 1977 14880372 Asia 38.438 786.1134 14.880372 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +On a single graph, plot population, in +millions, against year, for all countries. Do not worry about +identifying which country is which. + +Repeat the exercise, graphing only for China, India, and +Indonesia. Again, do not worry about which is which. + +::::::::::::::: solution + +## Solution to challenge 2 + +Refresh your plotting skills by plotting population in millions against year. + + +``` r +ggplot(gapminder, aes(x = year, y = pop_millions)) + + geom_point() +``` + +Scatter plot showing populations in the millions against the year for China, India, and Indonesia, countries are not labeled. + +``` r +countryset <- c("China","India","Indonesia") +ggplot(gapminder[gapminder$country %in% countryset,], + aes(x = year, y = pop_millions)) + + geom_point() +``` + +Scatter plot showing populations in the millions against the year for China, India, and Indonesia, countries are not labeled. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Comparison operators, logical operators, and many functions are also +vectorized: + +**Comparison operators** + + +``` r +x > 2 +``` + +``` output +[1] FALSE FALSE TRUE TRUE +``` + +**Logical operators** + + +``` r +a <- x > 3 # or, for clarity, a <- (x > 3) +a +``` + +``` output +[1] FALSE FALSE FALSE TRUE +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: some useful functions for logical vectors + +`any()` will return `TRUE` if *any* element of a vector is `TRUE`. +`all()` will return `TRUE` if *all* elements of a vector are `TRUE`. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Most functions also operate element-wise on vectors: + +**Functions** + + +``` r +x <- 1:4 +log(x) +``` + +``` output +[1] 0.0000000 0.6931472 1.0986123 1.3862944 +``` + +Vectorized operations work element-wise on matrices: + + +``` r +m <- matrix(1:12, nrow=3, ncol=4) +m * -1 +``` + +``` output + [,1] [,2] [,3] [,4] +[1,] -1 -4 -7 -10 +[2,] -2 -5 -8 -11 +[3,] -3 -6 -9 -12 +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: element-wise vs. matrix multiplication + +Very important: the operator `*` gives you element-wise multiplication! +To do matrix multiplication, we need to use the `%*%` operator: + + +``` r +m %*% matrix(1, nrow=4, ncol=1) +``` + +``` output + [,1] +[1,] 22 +[2,] 26 +[3,] 30 +``` + +``` r +matrix(1:4, nrow=1) %*% matrix(1:4, ncol=1) +``` + +``` output + [,1] +[1,] 30 +``` + +For more on matrix algebra, see the [Quick-R reference +guide](https://www.statmethods.net/advstats/matrix.html) + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Given the following matrix: + + +``` r +m <- matrix(1:12, nrow=3, ncol=4) +m +``` + +``` output + [,1] [,2] [,3] [,4] +[1,] 1 4 7 10 +[2,] 2 5 8 11 +[3,] 3 6 9 12 +``` + +Write down what you think will happen when you run: + +1. `m ^ -1` +2. `m * c(1, 0, -1)` +3. `m > c(0, 20)` +4. `m * c(1, 0, -1, 2)` + +Did you get the output you expected? If not, ask a helper! + +::::::::::::::: solution + +## Solution to challenge 3 + +Given the following matrix: + + +``` r +m <- matrix(1:12, nrow=3, ncol=4) +m +``` + +``` output + [,1] [,2] [,3] [,4] +[1,] 1 4 7 10 +[2,] 2 5 8 11 +[3,] 3 6 9 12 +``` + +Write down what you think will happen when you run: + +1. `m ^ -1` + + +``` output + [,1] [,2] [,3] [,4] +[1,] 1.0000000 0.2500000 0.1428571 0.10000000 +[2,] 0.5000000 0.2000000 0.1250000 0.09090909 +[3,] 0.3333333 0.1666667 0.1111111 0.08333333 +``` + +2. `m * c(1, 0, -1)` + + +``` output + [,1] [,2] [,3] [,4] +[1,] 1 4 7 10 +[2,] 0 0 0 0 +[3,] -3 -6 -9 -12 +``` + +3. `m > c(0, 20)` + + +``` output + [,1] [,2] [,3] [,4] +[1,] TRUE FALSE TRUE FALSE +[2,] FALSE TRUE FALSE TRUE +[3,] TRUE FALSE TRUE FALSE +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +We're interested in looking at the sum of the +following sequence of fractions: + + +``` r + x = 1/(1^2) + 1/(2^2) + 1/(3^2) + ... + 1/(n^2) +``` + +This would be tedious to type out, and impossible for high values of +n. Use vectorisation to compute x when n=100. What is the sum when +n=10,000? + +::::::::::::::: solution + +## Challenge 4 + +We're interested in looking at the sum of the +following sequence of fractions: + + +``` r + x = 1/(1^2) + 1/(2^2) + 1/(3^2) + ... + 1/(n^2) +``` + +This would be tedious to type out, and impossible for +high values of n. +Can you use vectorisation to compute x, when n=100? +How about when n=10,000? + + +``` r +sum(1/(1:100)^2) +``` + +``` output +[1] 1.634984 +``` + +``` r +sum(1/(1:1e04)^2) +``` + +``` output +[1] 1.644834 +``` + +``` r +n <- 10000 +sum(1/(1:n)^2) +``` + +``` output +[1] 1.644834 +``` + +We can also obtain the same results using a function: + + +``` r +inverse_sum_of_squares <- function(n) { + sum(1/(1:n)^2) +} +inverse_sum_of_squares(100) +``` + +``` output +[1] 1.634984 +``` + +``` r +inverse_sum_of_squares(10000) +``` + +``` output +[1] 1.644834 +``` + +``` r +n <- 10000 +inverse_sum_of_squares(n) +``` + +``` output +[1] 1.644834 +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Operations on vectors of unequal length + +Operations can also be performed on vectors of unequal length, through +a process known as *recycling*. This process automatically repeats the smaller vector +until it matches the length of the larger vector. R will provide a warning +if the larger vector is not a multiple of the smaller vector. + + +``` r +x <- c(1, 2, 3) +y <- c(1, 2, 3, 4, 5, 6, 7) +x + y +``` + +``` warning +Warning in x + y: longer object length is not a multiple of shorter object +length +``` + +``` output +[1] 2 4 6 5 7 9 8 +``` + +Vector `x` was recycled to match the length of vector `y` + + +``` r +x: 1 2 3 1 2 3 1 + + + + + + + + +y: 1 2 3 4 5 6 7 +----------------------- + 2 4 6 5 7 9 8 +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use vectorized operations instead of loops. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/10-functions.md b/10-functions.md new file mode 100644 index 000000000..a831b0b0d --- /dev/null +++ b/10-functions.md @@ -0,0 +1,685 @@ +--- +title: Functions Explained +teaching: 45 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Define a function that takes arguments. +- Return a value from a function. +- Check argument conditions with `stopifnot()` in functions. +- Test a function. +- Set default values for function arguments. +- Explain why we should divide programs into small, single-purpose functions. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I write a new function in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +If we only had one data set to analyze, it would probably be faster to load the +file into a spreadsheet and use that to plot simple statistics. However, the +gapminder data is updated periodically, and we may want to pull in that new +information later and re-run our analysis again. We may also obtain similar data +from a different source in the future. + +In this lesson, we'll learn how to write a function so that we can repeat +several operations with a single command. + +::::::::::::::::::::::::::::::::::::::::: callout + +## What is a function? + +Functions gather a sequence of operations into a whole, preserving it for +ongoing use. Functions provide: + +- a name we can remember and invoke it by +- relief from the need to remember the individual operations +- a defined set of inputs and expected outputs +- rich connections to the larger programming environment + +As the basic building block of most programming languages, user-defined +functions constitute "programming" as much as any single abstraction can. If +you have written a function, you are a computer programmer. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Defining a function + +Let's open a new R script file in the `functions/` directory and call it +functions-lesson.R. + +The general structure of a function is: + + +``` r +my_function <- function(parameters) { + # perform action + # return value +} +``` + +Let's define a function `fahr_to_kelvin()` that converts temperatures from +Fahrenheit to Kelvin: + + +``` r +fahr_to_kelvin <- function(temp) { + kelvin <- ((temp - 32) * (5 / 9)) + 273.15 + return(kelvin) +} +``` + +We define `fahr_to_kelvin()` by assigning it to the output of `function`. The +list of argument names are contained within parentheses. Next, the +[body](../learners/reference.md#body) of the function--the +statements that are executed when it runs--is contained within curly braces +(`{}`). The statements in the body are indented by two spaces. This makes the +code easier to read but does not affect how the code operates. + +It is useful to think of creating functions like writing a cookbook. First you define the "ingredients" that your function needs. In this case, we only need one ingredient to use our function: "temp". After we list our ingredients, we then say what we will do with them, in this case, we are taking our ingredient and applying a set of mathematical operators to it. + +When we call the function, the values we pass to it as arguments are assigned to +those variables so that we can use them inside the function. Inside the +function, we use a [return +statement](../learners/reference.md#return-statement) to send a result back to +whoever asked for it. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip + +One feature unique to R is that the return statement is not required. +R automatically returns whichever variable is on the last line of the body +of the function. But for clarity, we will explicitly define the +return statement. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Let's try running our function. +Calling our own function is no different from calling any other function: + + +``` r +# freezing point of water +fahr_to_kelvin(32) +``` + +``` output +[1] 273.15 +``` + + +``` r +# boiling point of water +fahr_to_kelvin(212) +``` + +``` output +[1] 373.15 +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Write a function called `kelvin_to_celsius()` that takes a temperature in +Kelvin and returns that temperature in Celsius. + +Hint: To convert from Kelvin to Celsius you subtract 273.15 + +::::::::::::::: solution + +## Solution to challenge 1 + +Write a function called `kelvin_to_celsius` that takes a temperature in Kelvin +and returns that temperature in Celsius + + +``` r +kelvin_to_celsius <- function(temp) { + celsius <- temp - 273.15 + return(celsius) +} +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Combining functions + +The real power of functions comes from mixing, matching and combining them +into ever-larger chunks to get the effect we want. + +Let's define two functions that will convert temperature from Fahrenheit to +Kelvin, and Kelvin to Celsius: + + +``` r +fahr_to_kelvin <- function(temp) { + kelvin <- ((temp - 32) * (5 / 9)) + 273.15 + return(kelvin) +} + +kelvin_to_celsius <- function(temp) { + celsius <- temp - 273.15 + return(celsius) +} +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Define the function to convert directly from Fahrenheit to Celsius, +by reusing the two functions above (or using your own functions if you +prefer). + +::::::::::::::: solution + +## Solution to challenge 2 + +Define the function to convert directly from Fahrenheit to Celsius, +by reusing these two functions above + + +``` r +fahr_to_celsius <- function(temp) { + temp_k <- fahr_to_kelvin(temp) + result <- kelvin_to_celsius(temp_k) + return(result) +} +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Interlude: Defensive Programming + +Now that we've begun to appreciate how writing functions provides an efficient +way to make R code re-usable and modular, we should note that it is important +to ensure that functions only work in their intended use-cases. Checking +function parameters is related to the concept of *defensive programming*. +Defensive programming encourages us to frequently check conditions and throw an +error if something is wrong. These checks are referred to as assertion +statements because we want to assert some condition is `TRUE` before proceeding. +They make it easier to debug because they give us a better idea of where the +errors originate. + +### Checking conditions with `stopifnot()` + +Let's start by re-examining `fahr_to_kelvin()`, our function for converting +temperatures from Fahrenheit to Kelvin. It was defined like so: + + +``` r +fahr_to_kelvin <- function(temp) { + kelvin <- ((temp - 32) * (5 / 9)) + 273.15 + return(kelvin) +} +``` + +For this function to work as intended, the argument `temp` must be a `numeric` +value; otherwise, the mathematical procedure for converting between the two +temperature scales will not work. To create an error, we can use the function +`stop()`. For example, since the argument `temp` must be a `numeric` vector, we +could check for this condition with an `if` statement and throw an error if the +condition was violated. We could augment our function above like so: + + +``` r +fahr_to_kelvin <- function(temp) { + if (!is.numeric(temp)) { + stop("temp must be a numeric vector.") + } + kelvin <- ((temp - 32) * (5 / 9)) + 273.15 + return(kelvin) +} +``` + +If we had multiple conditions or arguments to check, it would take many lines +of code to check all of them. Luckily R provides the convenience function +`stopifnot()`. We can list as many requirements that should evaluate to `TRUE`; +`stopifnot()` throws an error if it finds one that is `FALSE`. Listing these +conditions also serves a secondary purpose as extra documentation for the +function. + +Let's try out defensive programming with `stopifnot()` by adding assertions to +check the input to our function `fahr_to_kelvin()`. + +We want to assert the following: `temp` is a numeric vector. We may do that like +so: + + +``` r +fahr_to_kelvin <- function(temp) { + stopifnot(is.numeric(temp)) + kelvin <- ((temp - 32) * (5 / 9)) + 273.15 + return(kelvin) +} +``` + +It still works when given proper input. + + +``` r +# freezing point of water +fahr_to_kelvin(temp = 32) +``` + +``` output +[1] 273.15 +``` + +But fails instantly if given improper input. + + +``` r +# Metric is a factor instead of numeric +fahr_to_kelvin(temp = as.factor(32)) +``` + +``` error +Error in fahr_to_kelvin(temp = as.factor(32)): is.numeric(temp) is not TRUE +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Use defensive programming to ensure that our `fahr_to_celsius()` function +throws an error immediately if the argument `temp` is specified +inappropriately. + +::::::::::::::: solution + +## Solution to challenge 3 + +Extend our previous definition of the function by adding in an explicit call +to `stopifnot()`. Since `fahr_to_celsius()` is a composition of two other +functions, checking inside here makes adding checks to the two component +functions redundant. + + +``` r +fahr_to_celsius <- function(temp) { + stopifnot(is.numeric(temp)) + temp_k <- fahr_to_kelvin(temp) + result <- kelvin_to_celsius(temp_k) + return(result) +} +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## More on combining functions + +Now, we're going to define a function that calculates the Gross Domestic Product +of a nation from the data available in our dataset: + + +``` r +# Takes a dataset and multiplies the population column +# with the GDP per capita column. +calcGDP <- function(dat) { + gdp <- dat$pop * dat$gdpPercap + return(gdp) +} +``` + +We define `calcGDP()` by assigning it to the output of `function`. The list of +argument names are contained within parentheses. Next, the body of the function +\-- the statements executed when you call the function -- is contained within +curly braces (`{}`). + +We've indented the statements in the body by two spaces. This makes the code +easier to read but does not affect how it operates. + +When we call the function, the values we pass to it are assigned to the +arguments, which become variables inside the body of the function. + +Inside the function, we use the `return()` function to send back the result. +This `return()` function is optional: R will automatically return the results of +whatever command is executed on the last line of the function. + + +``` r +calcGDP(head(gapminder)) +``` + +``` output +[1] 6567086330 7585448670 8758855797 9648014150 9678553274 11697659231 +``` + +That's not very informative. Let's add some more arguments so we can extract +that per year and country. + + +``` r +# Takes a dataset and multiplies the population column +# with the GDP per capita column. +calcGDP <- function(dat, year=NULL, country=NULL) { + if(!is.null(year)) { + dat <- dat[dat$year %in% year, ] + } + if (!is.null(country)) { + dat <- dat[dat$country %in% country,] + } + gdp <- dat$pop * dat$gdpPercap + + new <- cbind(dat, gdp=gdp) + return(new) +} +``` + +If you've been writing these functions down into a separate R script +(a good idea!), you can load in the functions into our R session by using the +`source()` function: + + +``` r +source("functions/functions-lesson.R") +``` + +Ok, so there's a lot going on in this function now. In plain English, the +function now subsets the provided data by year if the year argument isn't empty, +then subsets the result by country if the country argument isn't empty. Then it +calculates the GDP for whatever subset emerges from the previous two steps. The +function then adds the GDP as a new column to the subsetted data and returns +this as the final result. You can see that the output is much more informative +than a vector of numbers. + +Let's take a look at what happens when we specify the year: + + +``` r +head(calcGDP(gapminder, year=2007)) +``` + +``` output + country year pop continent lifeExp gdpPercap gdp +12 Afghanistan 2007 31889923 Asia 43.828 974.5803 31079291949 +24 Albania 2007 3600523 Europe 76.423 5937.0295 21376411360 +36 Algeria 2007 33333216 Africa 72.301 6223.3675 207444851958 +48 Angola 2007 12420476 Africa 42.731 4797.2313 59583895818 +60 Argentina 2007 40301927 Americas 75.320 12779.3796 515033625357 +72 Australia 2007 20434176 Oceania 81.235 34435.3674 703658358894 +``` + +Or for a specific country: + + +``` r +calcGDP(gapminder, country="Australia") +``` + +``` output + country year pop continent lifeExp gdpPercap gdp +61 Australia 1952 8691212 Oceania 69.120 10039.60 87256254102 +62 Australia 1957 9712569 Oceania 70.330 10949.65 106349227169 +63 Australia 1962 10794968 Oceania 70.930 12217.23 131884573002 +64 Australia 1967 11872264 Oceania 71.100 14526.12 172457986742 +65 Australia 1972 13177000 Oceania 71.930 16788.63 221223770658 +66 Australia 1977 14074100 Oceania 73.490 18334.20 258037329175 +67 Australia 1982 15184200 Oceania 74.740 19477.01 295742804309 +68 Australia 1987 16257249 Oceania 76.320 21888.89 355853119294 +69 Australia 1992 17481977 Oceania 77.560 23424.77 409511234952 +70 Australia 1997 18565243 Oceania 78.830 26997.94 501223252921 +71 Australia 2002 19546792 Oceania 80.370 30687.75 599847158654 +72 Australia 2007 20434176 Oceania 81.235 34435.37 703658358894 +``` + +Or both: + + +``` r +calcGDP(gapminder, year=2007, country="Australia") +``` + +``` output + country year pop continent lifeExp gdpPercap gdp +72 Australia 2007 20434176 Oceania 81.235 34435.37 703658358894 +``` + +Let's walk through the body of the function: + + +``` r +calcGDP <- function(dat, year=NULL, country=NULL) { +``` + +Here we've added two arguments, `year`, and `country`. We've set +*default arguments* for both as `NULL` using the `=` operator +in the function definition. This means that those arguments will +take on those values unless the user specifies otherwise. + + +``` r + if(!is.null(year)) { + dat <- dat[dat$year %in% year, ] + } + if (!is.null(country)) { + dat <- dat[dat$country %in% country,] + } +``` + +Here, we check whether each additional argument is set to `null`, and whenever +they're not `null` overwrite the dataset stored in `dat` with a subset given by +the non-`null` argument. + +Building these conditionals into the function makes it more flexible for later. +Now, we can use it to calculate the GDP for: + +- The whole dataset; +- A single year; +- A single country; +- A single combination of year and country. + +By using `%in%` instead, we can also give multiple years or countries to those +arguments. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Pass by value + +Functions in R almost always make copies of the data to operate on +inside of a function body. When we modify `dat` inside the function +we are modifying the copy of the gapminder dataset stored in `dat`, +not the original variable we gave as the first argument. + +This is called "pass-by-value" and it makes writing code much safer: +you can always be sure that whatever changes you make within the +body of the function, stay inside the body of the function. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Function scope + +Another important concept is scoping: any variables (or functions!) you +create or modify inside the body of a function only exist for the lifetime +of the function's execution. When we call `calcGDP()`, the variables `dat`, +`gdp` and `new` only exist inside the body of the function. Even if we +have variables of the same name in our interactive R session, they are +not modified in any way when executing a function. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +``` r + gdp <- dat$pop * dat$gdpPercap + new <- cbind(dat, gdp=gdp) + return(new) +} +``` + +Finally, we calculated the GDP on our new subset, and created a new data frame +with that column added. This means when we call the function later we can see +the context for the returned GDP values, which is much better than in our first +attempt where we got a vector of numbers. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +Test out your GDP function by calculating the GDP for New Zealand in 1987. How +does this differ from New Zealand's GDP in 1952? + +::::::::::::::: solution + +## Solution to challenge 4 + + +``` r + calcGDP(gapminder, year = c(1952, 1987), country = "New Zealand") +``` + +GDP for New Zealand in 1987: 65050008703 + +GDP for New Zealand in 1952: 21058193787 + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 5 + +The `paste()` function can be used to combine text together, e.g: + + +``` r +best_practice <- c("Write", "programs", "for", "people", "not", "computers") +paste(best_practice, collapse=" ") +``` + +``` output +[1] "Write programs for people not computers" +``` + +Write a function called `fence()` that takes two vectors as arguments, called +`text` and `wrapper`, and prints out the text wrapped with the `wrapper`: + + +``` r +fence(text=best_practice, wrapper="***") +``` + +*Note:* the `paste()` function has an argument called `sep`, which specifies +the separator between text. The default is a space: " ". The default for +`paste0()` is no space "". + +::::::::::::::: solution + +## Solution to challenge 5 + +Write a function called `fence()` that takes two vectors as arguments, +called `text` and `wrapper`, and prints out the text wrapped with the +`wrapper`: + + +``` r +fence <- function(text, wrapper){ + text <- c(wrapper, text, wrapper) + result <- paste(text, collapse = " ") + return(result) +} +best_practice <- c("Write", "programs", "for", "people", "not", "computers") +fence(text=best_practice, wrapper="***") +``` + +``` output +[1] "*** Write programs for people not computers ***" +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip + +R has some unique aspects that can be exploited when performing more +complicated operations. We will not be writing anything that requires +knowledge of these more advanced concepts. In the future when you are +comfortable writing functions in R, you can learn more by reading the +[R Language Manual][man] or this [chapter] from +[Advanced R Programming][adv-r] by Hadley Wickham. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Testing and documenting + +It's important to both test functions and document them: +Documentation helps you, and others, understand what the +purpose of your function is, and how to use it, and its +important to make sure that your function actually does +what you think. + +When you first start out, your workflow will probably look a lot +like this: + +1. Write a function +2. Comment parts of the function to document its behaviour +3. Load in the source file +4. Experiment with it in the console to make sure it behaves + as you expect +5. Make any necessary bug fixes +6. Rinse and repeat. + +Formal documentation for functions, written in separate `.Rd` +files, gets turned into the documentation you see in help +files. The [roxygen2] package allows R coders to write documentation +alongside the function code and then process it into the appropriate `.Rd` +files. You will want to switch to this more formal method of writing +documentation when you start writing more complicated R projects. In fact, +packages are, in essence, bundles of functions with this formal documentation. +Loading your own functions through `source("functions.R")` is equivalent to +loading someone else's functions (or your own one day!) through +`library("package")`. + +Formal automated tests can be written using the [testthat] package. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +[man]: https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Environment-objects +[chapter]: https://adv-r.had.co.nz/Environments.html +[adv-r]: https://adv-r.had.co.nz/ +[roxygen2]: https://cran.r-project.org/web/packages/roxygen2/vignettes/rd.html +[testthat]: https://r-pkgs.had.co.nz/tests.html + + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `function` to define a new function in R. +- Use parameters to pass values into functions. +- Use `stopifnot()` to flexibly check function arguments in R. +- Load functions into programs using `source()`. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/11-writing-data.md b/11-writing-data.md new file mode 100644 index 000000000..d28fcdf9c --- /dev/null +++ b/11-writing-data.md @@ -0,0 +1,217 @@ +--- +title: Writing Data +teaching: 10 +exercises: 10 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To be able to write out plots and data from R. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I save plots and data created in R? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +## Saving plots + +You have already seen how to save the most recent plot you create in `ggplot2`, +using the command `ggsave`. As a refresher: + + +``` r +ggsave("My_most_recent_plot.pdf") +``` + +You can save a plot from within RStudio using the 'Export' button +in the 'Plot' window. This will give you the option of saving as a +.pdf or as .png, .jpg or other image formats. + +Sometimes you will want to save plots without creating them in the +'Plot' window first. Perhaps you want to make a pdf document with +multiple pages: each one a different plot, for example. Or perhaps +you're looping through multiple subsets of a file, plotting data from +each subset, and you want to save each plot, but obviously can't stop +the loop to click 'Export' for each one. + +In this case you can use a more flexible approach. The function +`pdf` creates a new pdf device. You can control the size and resolution +using the arguments to this function. + + +``` r +pdf("Life_Exp_vs_time.pdf", width=12, height=4) +ggplot(data=gapminder, aes(x=year, y=lifeExp, colour=country)) + + geom_line() + + theme(legend.position = "none") + +# You then have to make sure to turn off the pdf device! + +dev.off() +``` + +Open up this document and have a look. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Rewrite your 'pdf' command to print a second +page in the pdf, showing a facet plot (hint: use `facet_grid`) +of the same data with one panel per continent. + +::::::::::::::: solution + +## Solution to challenge 1 + + +``` r +pdf("Life_Exp_vs_time.pdf", width = 12, height = 4) +p <- ggplot(data = gapminder, aes(x = year, y = lifeExp, colour = country)) + + geom_line() + + theme(legend.position = "none") +p +p + facet_grid(~continent) +dev.off() +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +The commands `jpeg`, `png` etc. are used similarly to produce +documents in different formats. + +## Writing data + +At some point, you'll also want to write out data from R. + +We can use the `write.table` function for this, which is +very similar to `read.table` from before. + +Let's create a data-cleaning script, for this analysis, we +only want to focus on the gapminder data for Australia: + + +``` r +aust_subset <- gapminder[gapminder$country == "Australia",] + +write.table(aust_subset, + file="cleaned-data/gapminder-aus.csv", + sep="," +) +``` + +Let's switch back to the shell to take a look at the data to make sure it looks +OK: + + +``` bash +head cleaned-data/gapminder-aus.csv +``` + +``` output +"country","year","pop","continent","lifeExp","gdpPercap" +"61","Australia",1952,8691212,"Oceania",69.12,10039.59564 +"62","Australia",1957,9712569,"Oceania",70.33,10949.64959 +"63","Australia",1962,10794968,"Oceania",70.93,12217.22686 +"64","Australia",1967,11872264,"Oceania",71.1,14526.12465 +"65","Australia",1972,13177000,"Oceania",71.93,16788.62948 +"66","Australia",1977,14074100,"Oceania",73.49,18334.19751 +"67","Australia",1982,15184200,"Oceania",74.74,19477.00928 +"68","Australia",1987,16257249,"Oceania",76.32,21888.88903 +"69","Australia",1992,17481977,"Oceania",77.56,23424.76683 +``` + +Hmm, that's not quite what we wanted. Where did all these +quotation marks come from? Also the row numbers are +meaningless. + +Let's look at the help file to work out how to change this +behaviour. + + +``` r +?write.table +``` + +By default R will wrap character vectors with quotation marks +when writing out to file. It will also write out the row and +column names. + +Let's fix this: + + +``` r +write.table( + gapminder[gapminder$country == "Australia",], + file="cleaned-data/gapminder-aus.csv", + sep=",", quote=FALSE, row.names=FALSE +) +``` + +Now lets look at the data again using our shell skills: + + +``` bash +head cleaned-data/gapminder-aus.csv +``` + +``` output +country,year,pop,continent,lifeExp,gdpPercap +Australia,1952,8691212,Oceania,69.12,10039.59564 +Australia,1957,9712569,Oceania,70.33,10949.64959 +Australia,1962,10794968,Oceania,70.93,12217.22686 +Australia,1967,11872264,Oceania,71.1,14526.12465 +Australia,1972,13177000,Oceania,71.93,16788.62948 +Australia,1977,14074100,Oceania,73.49,18334.19751 +Australia,1982,15184200,Oceania,74.74,19477.00928 +Australia,1987,16257249,Oceania,76.32,21888.88903 +Australia,1992,17481977,Oceania,77.56,23424.76683 +``` + +That looks better! + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Write a data-cleaning script file that subsets the gapminder +data to include only data points collected since 1990. + +Use this script to write out the new subset to a file +in the `cleaned-data/` directory. + +::::::::::::::: solution + +## Solution to challenge 2 + + +``` r +write.table( + gapminder[gapminder$year > 1990, ], + file = "cleaned-data/gapminder-after1990.csv", + sep = ",", quote = FALSE, row.names = FALSE +) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Save plots from RStudio using the 'Export' button. +- Use `write.table` to save tabular data. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/12-dplyr.md b/12-dplyr.md new file mode 100644 index 000000000..8d7dfa4b2 --- /dev/null +++ b/12-dplyr.md @@ -0,0 +1,672 @@ +--- +title: Data Frame Manipulation with dplyr +teaching: 40 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To be able to use the six main data frame manipulation 'verbs' with pipes in `dplyr`. +- To understand how `group_by()` and `summarize()` can be combined to summarize datasets. +- Be able to analyze a subset of data using logical filtering. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I manipulate data frames without repeating myself? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +Manipulation of data frames means many things to many researchers: we often +select certain observations (rows) or variables (columns), we often group the +data by a certain variable(s), or we even calculate summary statistics. We can +do these operations using the normal base R operations: + + +``` r +mean(gapminder$gdpPercap[gapminder$continent == "Africa"]) +``` + +``` output +[1] 2193.755 +``` + +``` r +mean(gapminder$gdpPercap[gapminder$continent == "Americas"]) +``` + +``` output +[1] 7136.11 +``` + +``` r +mean(gapminder$gdpPercap[gapminder$continent == "Asia"]) +``` + +``` output +[1] 7902.15 +``` + +But this isn't very *nice* because there is a fair bit of repetition. Repeating +yourself will cost you time, both now and later, and potentially introduce some +nasty bugs. + +## The `dplyr` package + +Luckily, the [`dplyr`](https://cran.r-project.org/package=dplyr) +package provides a number of very useful functions for manipulating data frames +in a way that will reduce the above repetition, reduce the probability of making +errors, and probably even save you some typing. As an added bonus, you might +even find the `dplyr` grammar easier to read. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Tidyverse + +`dplyr` package belongs to a broader family of opinionated R packages +designed for data science called the "Tidyverse". These +packages are specifically designed to work harmoniously together. +Some of these packages will be covered along this course, but you can find more +complete information here: [https://www.tidyverse.org/](https://www.tidyverse.org/). + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Here we're going to cover 5 of the most commonly used functions as well as using +pipes (`%>%`) to combine them. + +1. `select()` +2. `filter()` +3. `group_by()` +4. `summarize()` +5. `mutate()` + +If you have have not installed this package earlier, please do so: + + +``` r +install.packages('dplyr') +``` + +Now let's load the package: + + +``` r +library("dplyr") +``` + +## Using select() + +If, for example, we wanted to move forward with only a few of the variables in +our data frame we could use the `select()` function. This will keep only the +variables you select. + + +``` r +year_country_gdp <- select(gapminder, year, country, gdpPercap) +``` + +![](fig/13-dplyr-fig1.png){alt='Diagram illustrating use of select function to select two columns of a data frame'} +If we want to remove one column only from the `gapminder` data, for example, +removing the `continent` column. + + +``` r +smaller_gapminder_data <- select(gapminder, -continent) +``` + +If we open up `year_country_gdp` we'll see that it only contains the year, +country and gdpPercap. Above we used 'normal' grammar, but the strengths of +`dplyr` lie in combining several functions using pipes. Since the pipes grammar +is unlike anything we've seen in R before, let's repeat what we've done above +using pipes. + + +``` r +year_country_gdp <- gapminder %>% select(year, country, gdpPercap) +``` + +To help you understand why we wrote that in that way, let's walk through it step +by step. First we summon the gapminder data frame and pass it on, using the pipe +symbol `%>%`, to the next step, which is the `select()` function. In this case +we don't specify which data object we use in the `select()` function since in +gets that from the previous pipe. **Fun Fact**: There is a good chance you have +encountered pipes before in the shell. In R, a pipe symbol is `%>%` while in the +shell it is `|` but the concept is the same! + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Renaming data frame columns in dplyr + +In Chapter 4 we covered how you can rename columns with base R by assigning a value to the output of the `names()` function. +Just like select, this is a bit cumbersome, but thankfully dplyr has a `rename()` function. + +Within a pipeline, the syntax is `rename(new_name = old_name)`. +For example, we may want to rename the gdpPercap column name from our `select()` statement above. + + +``` r +tidy_gdp <- year_country_gdp %>% rename(gdp_per_capita = gdpPercap) + +head(tidy_gdp) +``` + +``` output + year country gdp_per_capita +1 1952 Afghanistan 779.4453 +2 1957 Afghanistan 820.8530 +3 1962 Afghanistan 853.1007 +4 1967 Afghanistan 836.1971 +5 1972 Afghanistan 739.9811 +6 1977 Afghanistan 786.1134 +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Using filter() + +If we now want to move forward with the above, but only with European +countries, we can combine `select` and `filter` + + +``` r +year_country_gdp_euro <- gapminder %>% + filter(continent == "Europe") %>% + select(year, country, gdpPercap) +``` + +If we now want to show life expectancy of European countries but only +for a specific year (e.g., 2007), we can do as below. + + +``` r +europe_lifeExp_2007 <- gapminder %>% + filter(continent == "Europe", year == 2007) %>% + select(country, lifeExp) +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Write a single command (which can span multiple lines and includes pipes) that +will produce a data frame that has the African values for `lifeExp`, `country` +and `year`, but not for other Continents. How many rows does your data frame +have and why? + +::::::::::::::: solution + +## Solution to Challenge 1 + + +``` r +year_country_lifeExp_Africa <- gapminder %>% + filter(continent == "Africa") %>% + select(year, country, lifeExp) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +As with last time, first we pass the gapminder data frame to the `filter()` +function, then we pass the filtered version of the gapminder data frame to the +`select()` function. **Note:** The order of operations is very important in this +case. If we used 'select' first, filter would not be able to find the variable +continent since we would have removed it in the previous step. + +## Using group\_by() + +Now, we were supposed to be reducing the error prone repetitiveness of what can +be done with base R, but up to now we haven't done that since we would have to +repeat the above for each continent. Instead of `filter()`, which will only pass +observations that meet your criteria (in the above: `continent=="Europe"`), we +can use `group_by()`, which will essentially use every unique criteria that you +could have used in filter. + + +``` r +str(gapminder) +``` + +``` output +'data.frame': 1704 obs. of 6 variables: + $ country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ... + $ year : int 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ... + $ pop : num 8425333 9240934 10267083 11537966 13079460 ... + $ continent: chr "Asia" "Asia" "Asia" "Asia" ... + $ lifeExp : num 28.8 30.3 32 34 36.1 ... + $ gdpPercap: num 779 821 853 836 740 ... +``` + +``` r +str(gapminder %>% group_by(continent)) +``` + +``` output +gropd_df [1,704 × 6] (S3: grouped_df/tbl_df/tbl/data.frame) + $ country : chr [1:1704] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ... + $ year : int [1:1704] 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ... + $ pop : num [1:1704] 8425333 9240934 10267083 11537966 13079460 ... + $ continent: chr [1:1704] "Asia" "Asia" "Asia" "Asia" ... + $ lifeExp : num [1:1704] 28.8 30.3 32 34 36.1 ... + $ gdpPercap: num [1:1704] 779 821 853 836 740 ... + - attr(*, "groups")= tibble [5 × 2] (S3: tbl_df/tbl/data.frame) + ..$ continent: chr [1:5] "Africa" "Americas" "Asia" "Europe" ... + ..$ .rows : list [1:5] + .. ..$ : int [1:624] 25 26 27 28 29 30 31 32 33 34 ... + .. ..$ : int [1:300] 49 50 51 52 53 54 55 56 57 58 ... + .. ..$ : int [1:396] 1 2 3 4 5 6 7 8 9 10 ... + .. ..$ : int [1:360] 13 14 15 16 17 18 19 20 21 22 ... + .. ..$ : int [1:24] 61 62 63 64 65 66 67 68 69 70 ... + .. ..@ ptype: int(0) + ..- attr(*, ".drop")= logi TRUE +``` + +You will notice that the structure of the data frame where we used `group_by()` +(`grouped_df`) is not the same as the original `gapminder` (`data.frame`). A +`grouped_df` can be thought of as a `list` where each item in the `list`is a +`data.frame` which contains only the rows that correspond to the a particular +value `continent` (at least in the example above). + +![](fig/13-dplyr-fig2.png){alt='Diagram illustrating how the group by function oraganizes a data frame into groups'} + +## Using summarize() + +The above was a bit on the uneventful side but `group_by()` is much more +exciting in conjunction with `summarize()`. This will allow us to create new +variable(s) by using functions that repeat for each of the continent-specific +data frames. That is to say, using the `group_by()` function, we split our +original data frame into multiple pieces, then we can run functions +(e.g. `mean()` or `sd()`) within `summarize()`. + + +``` r +gdp_bycontinents <- gapminder %>% + group_by(continent) %>% + summarize(mean_gdpPercap = mean(gdpPercap)) +``` + +![](fig/13-dplyr-fig3.png){alt='Diagram illustrating the use of group by and summarize together to create a new variable'} + + +``` r +continent mean_gdpPercap + +1 Africa 2193.755 +2 Americas 7136.110 +3 Asia 7902.150 +4 Europe 14469.476 +5 Oceania 18621.609 +``` + +That allowed us to calculate the mean gdpPercap for each continent, but it gets +even better. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Calculate the average life expectancy per country. Which has the longest average life +expectancy and which has the shortest average life expectancy? + +::::::::::::::: solution + +## Solution to Challenge 2 + + +``` r +lifeExp_bycountry <- gapminder %>% + group_by(country) %>% + summarize(mean_lifeExp = mean(lifeExp)) +lifeExp_bycountry %>% + filter(mean_lifeExp == min(mean_lifeExp) | mean_lifeExp == max(mean_lifeExp)) +``` + +``` output +# A tibble: 2 × 2 + country mean_lifeExp + +1 Iceland 76.5 +2 Sierra Leone 36.8 +``` + +Another way to do this is to use the `dplyr` function `arrange()`, which +arranges the rows in a data frame according to the order of one or more +variables from the data frame. It has similar syntax to other functions from +the `dplyr` package. You can use `desc()` inside `arrange()` to sort in +descending order. + + +``` r +lifeExp_bycountry %>% + arrange(mean_lifeExp) %>% + head(1) +``` + +``` output +# A tibble: 1 × 2 + country mean_lifeExp + +1 Sierra Leone 36.8 +``` + +``` r +lifeExp_bycountry %>% + arrange(desc(mean_lifeExp)) %>% + head(1) +``` + +``` output +# A tibble: 1 × 2 + country mean_lifeExp + +1 Iceland 76.5 +``` + +Alphabetical order works too + + +``` r +lifeExp_bycountry %>% + arrange(desc(country)) %>% + head(1) +``` + +``` output +# A tibble: 1 × 2 + country mean_lifeExp + +1 Zimbabwe 52.7 +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::: + +The function `group_by()` allows us to group by multiple variables. Let's group by `year` and `continent`. + + +``` r +gdp_bycontinents_byyear <- gapminder %>% + group_by(continent, year) %>% + summarize(mean_gdpPercap = mean(gdpPercap)) +``` + +``` output +`summarise()` has grouped output by 'continent'. You can override using the +`.groups` argument. +``` + +That is already quite powerful, but it gets even better! You're not limited to defining 1 new variable in `summarize()`. + + +``` r +gdp_pop_bycontinents_byyear <- gapminder %>% + group_by(continent, year) %>% + summarize(mean_gdpPercap = mean(gdpPercap), + sd_gdpPercap = sd(gdpPercap), + mean_pop = mean(pop), + sd_pop = sd(pop)) +``` + +``` output +`summarise()` has grouped output by 'continent'. You can override using the +`.groups` argument. +``` + +## count() and n() + +A very common operation is to count the number of observations for each +group. The `dplyr` package comes with two related functions that help with this. + +For instance, if we wanted to check the number of countries included in the +dataset for the year 2002, we can use the `count()` function. It takes the name +of one or more columns that contain the groups we are interested in, and we can +optionally sort the results in descending order by adding `sort=TRUE`: + + +``` r +gapminder %>% + filter(year == 2002) %>% + count(continent, sort = TRUE) +``` + +``` output + continent n +1 Africa 52 +2 Asia 33 +3 Europe 30 +4 Americas 25 +5 Oceania 2 +``` + +If we need to use the number of observations in calculations, the `n()` function +is useful. It will return the total number of observations in the current group rather than counting the number of observations in each group within a specific column. For instance, if we wanted to get the standard error of the life expectency per continent: + + +``` r +gapminder %>% + group_by(continent) %>% + summarize(se_le = sd(lifeExp)/sqrt(n())) +``` + +``` output +# A tibble: 5 × 2 + continent se_le + +1 Africa 0.366 +2 Americas 0.540 +3 Asia 0.596 +4 Europe 0.286 +5 Oceania 0.775 +``` + +You can also chain together several summary operations; in this case calculating the `minimum`, `maximum`, `mean` and `se` of each continent's per-country life-expectancy: + + +``` r +gapminder %>% + group_by(continent) %>% + summarize( + mean_le = mean(lifeExp), + min_le = min(lifeExp), + max_le = max(lifeExp), + se_le = sd(lifeExp)/sqrt(n())) +``` + +``` output +# A tibble: 5 × 5 + continent mean_le min_le max_le se_le + +1 Africa 48.9 23.6 76.4 0.366 +2 Americas 64.7 37.6 80.7 0.540 +3 Asia 60.1 28.8 82.6 0.596 +4 Europe 71.9 43.6 81.8 0.286 +5 Oceania 74.3 69.1 81.2 0.775 +``` + +## Using mutate() + +We can also create new variables prior to (or even after) summarizing information using `mutate()`. + + +``` r +gdp_pop_bycontinents_byyear <- gapminder %>% + mutate(gdp_billion = gdpPercap*pop/10^9) %>% + group_by(continent,year) %>% + summarize(mean_gdpPercap = mean(gdpPercap), + sd_gdpPercap = sd(gdpPercap), + mean_pop = mean(pop), + sd_pop = sd(pop), + mean_gdp_billion = mean(gdp_billion), + sd_gdp_billion = sd(gdp_billion)) +``` + +``` output +`summarise()` has grouped output by 'continent'. You can override using the +`.groups` argument. +``` + +## Connect mutate with logical filtering: ifelse + +When creating new variables, we can hook this with a logical condition. A simple combination of +`mutate()` and `ifelse()` facilitates filtering right where it is needed: in the moment of creating something new. +This easy-to-read statement is a fast and powerful way of discarding certain data (even though the overall dimension +of the data frame will not change) or for updating values depending on this given condition. + + +``` r +## keeping all data but "filtering" after a certain condition +# calculate GDP only for people with a life expectation above 25 +gdp_pop_bycontinents_byyear_above25 <- gapminder %>% + mutate(gdp_billion = ifelse(lifeExp > 25, gdpPercap * pop / 10^9, NA)) %>% + group_by(continent, year) %>% + summarize(mean_gdpPercap = mean(gdpPercap), + sd_gdpPercap = sd(gdpPercap), + mean_pop = mean(pop), + sd_pop = sd(pop), + mean_gdp_billion = mean(gdp_billion), + sd_gdp_billion = sd(gdp_billion)) +``` + +``` output +`summarise()` has grouped output by 'continent'. You can override using the +`.groups` argument. +``` + +``` r +## updating only if certain condition is fullfilled +# for life expectations above 40 years, the gpd to be expected in the future is scaled +gdp_future_bycontinents_byyear_high_lifeExp <- gapminder %>% + mutate(gdp_futureExpectation = ifelse(lifeExp > 40, gdpPercap * 1.5, gdpPercap)) %>% + group_by(continent, year) %>% + summarize(mean_gdpPercap = mean(gdpPercap), + mean_gdpPercap_expected = mean(gdp_futureExpectation)) +``` + +``` output +`summarise()` has grouped output by 'continent'. You can override using the +`.groups` argument. +``` + +## Combining `dplyr` and `ggplot2` + +First install and load ggplot2: + + +``` r +install.packages('ggplot2') +``` + + +``` r +library("ggplot2") +``` + +In the plotting lesson we looked at how to make a multi-panel figure by adding +a layer of facet panels using `ggplot2`. Here is the code we used (with some +extra comments): + + +``` r +# Filter countries located in the Americas +americas <- gapminder[gapminder$continent == "Americas", ] +# Make the plot +ggplot(data = americas, mapping = aes(x = year, y = lifeExp)) + + geom_line() + + facet_wrap( ~ country) + + theme(axis.text.x = element_text(angle = 45)) +``` + + + +This code makes the right plot but it also creates an intermediate variable +(`americas`) that we might not have any other uses for. Just as we used +`%>%` to pipe data along a chain of `dplyr` functions we can use it to pass data +to `ggplot()`. Because `%>%` replaces the first argument in a function we don't +need to specify the `data =` argument in the `ggplot()` function. By combining +`dplyr` and `ggplot2` functions we can make the same figure without creating any +new variables or modifying the data. + + +``` r +gapminder %>% + # Filter countries located in the Americas + filter(continent == "Americas") %>% + # Make the plot + ggplot(mapping = aes(x = year, y = lifeExp)) + + geom_line() + + facet_wrap( ~ country) + + theme(axis.text.x = element_text(angle = 45)) +``` + + + +More examples of using the function `mutate()` and the `ggplot2` package. + + +``` r +gapminder %>% + # extract first letter of country name into new column + mutate(startsWith = substr(country, 1, 1)) %>% + # only keep countries starting with A or Z + filter(startsWith %in% c("A", "Z")) %>% + # plot lifeExp into facets + ggplot(aes(x = year, y = lifeExp, colour = continent)) + + geom_line() + + facet_wrap(vars(country)) + + theme_minimal() +``` + + + +::::::::::::::::::::::::::::::::::::::: challenge + +## Advanced Challenge + +Calculate the average life expectancy in 2002 of 2 randomly selected countries +for each continent. Then arrange the continent names in reverse order. +**Hint:** Use the `dplyr` functions `arrange()` and `sample_n()`, they have +similar syntax to other dplyr functions. + +::::::::::::::: solution + +## Solution to Advanced Challenge + + +``` r +lifeExp_2countries_bycontinents <- gapminder %>% + filter(year==2002) %>% + group_by(continent) %>% + sample_n(2) %>% + summarize(mean_lifeExp=mean(lifeExp)) %>% + arrange(desc(mean_lifeExp)) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Other great resources + +- [R for Data Science](https://r4ds.hadley.nz/) (online book) +- [Data Wrangling Cheat sheet](https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf) (pdf file) +- [Introduction to dplyr](https://dplyr.tidyverse.org/) (online documentation) +- [Data wrangling with R and RStudio](https://www.rstudio.com/resources/webinars/data-wrangling-with-r-and-rstudio/) (online video) +- [Tidyverse Skills for Data Science](https://jhudatascience.org/tidyversecourse/) (online book) + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use the `dplyr` package to manipulate data frames. +- Use `select()` to choose variables from a data frame. +- Use `filter()` to choose data based on values. +- Use `group_by()` and `summarize()` to work with subsets of data. +- Use `mutate()` to create new variables. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/13-tidyr.md b/13-tidyr.md new file mode 100644 index 000000000..9c49eb6b3 --- /dev/null +++ b/13-tidyr.md @@ -0,0 +1,605 @@ +--- +title: Data Frame Manipulation with tidyr +teaching: 30 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- To understand the concepts of 'longer' and 'wider' data frame formats and be able to convert between them with `tidyr`. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I change the layout of a data frame? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +Researchers often want to reshape their data frames from 'wide' to 'longer' +layouts, or vice-versa. The 'long' layout or format is where: + +- each column is a variable +- each row is an observation + +In the purely 'long' (or 'longest') format, you usually have 1 column for the observed variable and the other columns are ID variables. + +For the 'wide' format each row is often a site/subject/patient and you have +multiple observation variables containing the same type of data. These can be +either repeated observations over time, or observation of multiple variables (or +a mix of both). You may find data input may be simpler or some other +applications may prefer the 'wide' format. However, many of `R`'s functions have +been designed assuming you have 'longer' formatted data. This tutorial will help you +efficiently transform your data shape regardless of original format. + +![](fig/14-tidyr-fig1.png){alt='Diagram illustrating the difference between a wide versus long layout of a data frame'} + +Long and wide data frame layouts mainly affect readability. For humans, the wide format is often more intuitive since we can often see more of the data on the screen due +to its shape. However, the long format is more machine readable and is closer +to the formatting of databases. The ID variables in our data frames are similar to +the fields in a database and observed variables are like the database values. + +## Getting started + +First install the packages if you haven't already done so (you probably +installed dplyr in the previous lesson): + + +``` r +#install.packages("tidyr") +#install.packages("dplyr") +``` + +Load the packages + + +``` r +library("tidyr") +library("dplyr") +``` + +First, lets look at the structure of our original gapminder data frame: + + +``` r +str(gapminder) +``` + +``` output +'data.frame': 1704 obs. of 6 variables: + $ country : chr "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ... + $ year : int 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ... + $ pop : num 8425333 9240934 10267083 11537966 13079460 ... + $ continent: chr "Asia" "Asia" "Asia" "Asia" ... + $ lifeExp : num 28.8 30.3 32 34 36.1 ... + $ gdpPercap: num 779 821 853 836 740 ... +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Is gapminder a purely long, purely wide, or some intermediate format? + +::::::::::::::: solution + +## Solution to Challenge 1 + +The original gapminder data.frame is in an intermediate format. It is not +purely long since it had multiple observation variables +(`pop`,`lifeExp`,`gdpPercap`). + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Sometimes, as with the gapminder dataset, we have multiple types of observed +data. It is somewhere in between the purely 'long' and 'wide' data formats. We +have 3 "ID variables" (`continent`, `country`, `year`) and 3 "Observation +variables" (`pop`,`lifeExp`,`gdpPercap`). This intermediate format can be +preferred despite not having ALL observations in 1 column given that all 3 +observation variables have different units. There are few operations that would +need us to make this data frame any longer (i.e. 4 ID variables and 1 +Observation variable). + +While using many of the functions in R, which are often vector based, you +usually do not want to do mathematical operations on values with different +units. For example, using the purely long format, a single mean for all of the +values of population, life expectancy, and GDP would not be meaningful since it +would return the mean of values with 3 incompatible units. The solution is that +we first manipulate the data either by grouping (see the lesson on `dplyr`), or +we change the structure of the data frame. **Note:** Some plotting functions in +R actually work better in the wide format data. + +## From wide to long format with pivot\_longer() + +Until now, we've been using the nicely formatted original gapminder dataset, but +'real' data (i.e. our own research data) will never be so well organized. Here +let's start with the wide formatted version of the gapminder dataset. + +> Download the wide version of the gapminder data from [this link to a csv file](data/gapminder_wide.csv) +> and save it in your data folder. + +We'll load the data file and look at it. Note: we don't want our continent and +country columns to be factors, so we use the stringsAsFactors argument for +`read.csv()` to disable that. + + +``` r +gap_wide <- read.csv("data/gapminder_wide.csv", stringsAsFactors = FALSE) +str(gap_wide) +``` + +``` output +'data.frame': 142 obs. of 38 variables: + $ continent : chr "Africa" "Africa" "Africa" "Africa" ... + $ country : chr "Algeria" "Angola" "Benin" "Botswana" ... + $ gdpPercap_1952: num 2449 3521 1063 851 543 ... + $ gdpPercap_1957: num 3014 3828 960 918 617 ... + $ gdpPercap_1962: num 2551 4269 949 984 723 ... + $ gdpPercap_1967: num 3247 5523 1036 1215 795 ... + $ gdpPercap_1972: num 4183 5473 1086 2264 855 ... + $ gdpPercap_1977: num 4910 3009 1029 3215 743 ... + $ gdpPercap_1982: num 5745 2757 1278 4551 807 ... + $ gdpPercap_1987: num 5681 2430 1226 6206 912 ... + $ gdpPercap_1992: num 5023 2628 1191 7954 932 ... + $ gdpPercap_1997: num 4797 2277 1233 8647 946 ... + $ gdpPercap_2002: num 5288 2773 1373 11004 1038 ... + $ gdpPercap_2007: num 6223 4797 1441 12570 1217 ... + $ lifeExp_1952 : num 43.1 30 38.2 47.6 32 ... + $ lifeExp_1957 : num 45.7 32 40.4 49.6 34.9 ... + $ lifeExp_1962 : num 48.3 34 42.6 51.5 37.8 ... + $ lifeExp_1967 : num 51.4 36 44.9 53.3 40.7 ... + $ lifeExp_1972 : num 54.5 37.9 47 56 43.6 ... + $ lifeExp_1977 : num 58 39.5 49.2 59.3 46.1 ... + $ lifeExp_1982 : num 61.4 39.9 50.9 61.5 48.1 ... + $ lifeExp_1987 : num 65.8 39.9 52.3 63.6 49.6 ... + $ lifeExp_1992 : num 67.7 40.6 53.9 62.7 50.3 ... + $ lifeExp_1997 : num 69.2 41 54.8 52.6 50.3 ... + $ lifeExp_2002 : num 71 41 54.4 46.6 50.6 ... + $ lifeExp_2007 : num 72.3 42.7 56.7 50.7 52.3 ... + $ pop_1952 : num 9279525 4232095 1738315 442308 4469979 ... + $ pop_1957 : num 10270856 4561361 1925173 474639 4713416 ... + $ pop_1962 : num 11000948 4826015 2151895 512764 4919632 ... + $ pop_1967 : num 12760499 5247469 2427334 553541 5127935 ... + $ pop_1972 : num 14760787 5894858 2761407 619351 5433886 ... + $ pop_1977 : num 17152804 6162675 3168267 781472 5889574 ... + $ pop_1982 : num 20033753 7016384 3641603 970347 6634596 ... + $ pop_1987 : num 23254956 7874230 4243788 1151184 7586551 ... + $ pop_1992 : num 26298373 8735988 4981671 1342614 8878303 ... + $ pop_1997 : num 29072015 9875024 6066080 1536536 10352843 ... + $ pop_2002 : int 31287142 10866106 7026113 1630347 12251209 7021078 15929988 4048013 8835739 614382 ... + $ pop_2007 : int 33333216 12420476 8078314 1639131 14326203 8390505 17696293 4369038 10238807 710960 ... +``` + +![](fig/14-tidyr-fig2.png){alt='Diagram illustrating the wide format of the gapminder data frame'} + +To change this very wide data frame layout back to our nice, intermediate (or longer) layout, we will use one of the two available `pivot` functions from the `tidyr` package. To convert from wide to a longer format, we will use the `pivot_longer()` function. `pivot_longer()` makes datasets longer by increasing the number of rows and decreasing the number of columns, or 'lengthening' your observation variables into a single variable. + +![](fig/14-tidyr-fig3.png){alt='Diagram illustrating how pivot longer reorganizes a data frame from a wide to long format'} + + +``` r +gap_long <- gap_wide %>% + pivot_longer( + cols = c(starts_with('pop'), starts_with('lifeExp'), starts_with('gdpPercap')), + names_to = "obstype_year", values_to = "obs_values" + ) +str(gap_long) +``` + +``` output +tibble [5,112 × 4] (S3: tbl_df/tbl/data.frame) + $ continent : chr [1:5112] "Africa" "Africa" "Africa" "Africa" ... + $ country : chr [1:5112] "Algeria" "Algeria" "Algeria" "Algeria" ... + $ obstype_year: chr [1:5112] "pop_1952" "pop_1957" "pop_1962" "pop_1967" ... + $ obs_values : num [1:5112] 9279525 10270856 11000948 12760499 14760787 ... +``` + +Here we have used piping syntax which is similar to what we were doing in the +previous lesson with dplyr. In fact, these are compatible and you can use a mix +of tidyr and dplyr functions by piping them together. + +We first provide to `pivot_longer()` a vector of column names that will be +pivoted into longer format. We could type out all the observation variables, but +as in the `select()` function (see `dplyr` lesson), we can use the `starts_with()` +argument to select all variables that start with the desired character string. +`pivot_longer()` also allows the alternative syntax of using the `-` symbol to +identify which variables are not to be pivoted (i.e. ID variables). + +The next arguments to `pivot_longer()` are `names_to` for naming the column that +will contain the new ID variable (`obstype_year`) and `values_to` for naming the +new amalgamated observation variable (`obs_value`). We supply these new column +names as strings. + +![](fig/14-tidyr-fig4.png){alt='Diagram illustrating the long format of the gapminder data'} + + +``` r +gap_long <- gap_wide %>% + pivot_longer( + cols = c(-continent, -country), + names_to = "obstype_year", values_to = "obs_values" + ) +str(gap_long) +``` + +``` output +tibble [5,112 × 4] (S3: tbl_df/tbl/data.frame) + $ continent : chr [1:5112] "Africa" "Africa" "Africa" "Africa" ... + $ country : chr [1:5112] "Algeria" "Algeria" "Algeria" "Algeria" ... + $ obstype_year: chr [1:5112] "gdpPercap_1952" "gdpPercap_1957" "gdpPercap_1962" "gdpPercap_1967" ... + $ obs_values : num [1:5112] 2449 3014 2551 3247 4183 ... +``` + +That may seem trivial with this particular data frame, but sometimes you have 1 +ID variable and 40 observation variables with irregular variable names. The +flexibility is a huge time saver! + +Now `obstype_year` actually contains 2 pieces of information, the observation +type (`pop`,`lifeExp`, or `gdpPercap`) and the `year`. We can use the +`separate()` function to split the character strings into multiple variables + + +``` r +gap_long <- gap_long %>% separate(obstype_year, into = c('obs_type', 'year'), sep = "_") +gap_long$year <- as.integer(gap_long$year) +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Using `gap_long`, calculate the mean life expectancy, population, and gdpPercap for each continent. +**Hint:** use the `group_by()` and `summarize()` functions we learned in the `dplyr` lesson + +::::::::::::::: solution + +## Solution to Challenge 2 + + +``` r +gap_long %>% group_by(continent, obs_type) %>% + summarize(means=mean(obs_values)) +``` + +``` output +`summarise()` has grouped output by 'continent'. You can override using the +`.groups` argument. +``` + +``` output +# A tibble: 15 × 3 +# Groups: continent [5] + continent obs_type means + + 1 Africa gdpPercap 2194. + 2 Africa lifeExp 48.9 + 3 Africa pop 9916003. + 4 Americas gdpPercap 7136. + 5 Americas lifeExp 64.7 + 6 Americas pop 24504795. + 7 Asia gdpPercap 7902. + 8 Asia lifeExp 60.1 + 9 Asia pop 77038722. +10 Europe gdpPercap 14469. +11 Europe lifeExp 71.9 +12 Europe pop 17169765. +13 Oceania gdpPercap 18622. +14 Oceania lifeExp 74.3 +15 Oceania pop 8874672. +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## From long to intermediate format with pivot\_wider() + +It is always good to check work. So, let's use the second `pivot` function, `pivot_wider()`, to 'widen' our observation variables back out. `pivot_wider()` is the opposite of `pivot_longer()`, making a dataset wider by increasing the number of columns and decreasing the number of rows. We can use `pivot_wider()` to pivot or reshape our `gap_long` to the original intermediate format or the widest format. Let's start with the intermediate format. + +The `pivot_wider()` function takes `names_from` and `values_from` arguments. + +To `names_from` we supply the column name whose contents will be pivoted into new +output columns in the widened data frame. The corresponding values will be added +from the column named in the `values_from` argument. + + +``` r +gap_normal <- gap_long %>% + pivot_wider(names_from = obs_type, values_from = obs_values) +dim(gap_normal) +``` + +``` output +[1] 1704 6 +``` + +``` r +dim(gapminder) +``` + +``` output +[1] 1704 6 +``` + +``` r +names(gap_normal) +``` + +``` output +[1] "continent" "country" "year" "gdpPercap" "lifeExp" "pop" +``` + +``` r +names(gapminder) +``` + +``` output +[1] "country" "year" "pop" "continent" "lifeExp" "gdpPercap" +``` + +Now we've got an intermediate data frame `gap_normal` with the same dimensions as +the original `gapminder`, but the order of the variables is different. Let's fix +that before checking if they are `all.equal()`. + + +``` r +gap_normal <- gap_normal[, names(gapminder)] +all.equal(gap_normal, gapminder) +``` + +``` output +[1] "Attributes: < Component \"class\": Lengths (3, 1) differ (string compare on first 1) >" +[2] "Attributes: < Component \"class\": 1 string mismatch >" +[3] "Component \"country\": 1704 string mismatches" +[4] "Component \"pop\": Mean relative difference: 1.634504" +[5] "Component \"continent\": 1212 string mismatches" +[6] "Component \"lifeExp\": Mean relative difference: 0.203822" +[7] "Component \"gdpPercap\": Mean relative difference: 1.162302" +``` + +``` r +head(gap_normal) +``` + +``` output +# A tibble: 6 × 6 + country year pop continent lifeExp gdpPercap + +1 Algeria 1952 9279525 Africa 43.1 2449. +2 Algeria 1957 10270856 Africa 45.7 3014. +3 Algeria 1962 11000948 Africa 48.3 2551. +4 Algeria 1967 12760499 Africa 51.4 3247. +5 Algeria 1972 14760787 Africa 54.5 4183. +6 Algeria 1977 17152804 Africa 58.0 4910. +``` + +``` r +head(gapminder) +``` + +``` output + country year pop continent lifeExp gdpPercap +1 Afghanistan 1952 8425333 Asia 28.801 779.4453 +2 Afghanistan 1957 9240934 Asia 30.332 820.8530 +3 Afghanistan 1962 10267083 Asia 31.997 853.1007 +4 Afghanistan 1967 11537966 Asia 34.020 836.1971 +5 Afghanistan 1972 13079460 Asia 36.088 739.9811 +6 Afghanistan 1977 14880372 Asia 38.438 786.1134 +``` + +We're almost there, the original was sorted by `country`, then +`year`. + + +``` r +gap_normal <- gap_normal %>% arrange(country, year) +all.equal(gap_normal, gapminder) +``` + +``` output +[1] "Attributes: < Component \"class\": Lengths (3, 1) differ (string compare on first 1) >" +[2] "Attributes: < Component \"class\": 1 string mismatch >" +``` + +That's great! We've gone from the longest format back to the intermediate and we +didn't introduce any errors in our code. + +Now let's convert the long all the way back to the wide. In the wide format, we +will keep country and continent as ID variables and pivot the observations +across the 3 metrics (`pop`,`lifeExp`,`gdpPercap`) and time (`year`). First we +need to create appropriate labels for all our new variables (time\*metric +combinations) and we also need to unify our ID variables to simplify the process +of defining `gap_wide`. + + +``` r +gap_temp <- gap_long %>% unite(var_ID, continent, country, sep = "_") +str(gap_temp) +``` + +``` output +tibble [5,112 × 4] (S3: tbl_df/tbl/data.frame) + $ var_ID : chr [1:5112] "Africa_Algeria" "Africa_Algeria" "Africa_Algeria" "Africa_Algeria" ... + $ obs_type : chr [1:5112] "gdpPercap" "gdpPercap" "gdpPercap" "gdpPercap" ... + $ year : int [1:5112] 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ... + $ obs_values: num [1:5112] 2449 3014 2551 3247 4183 ... +``` + +``` r +gap_temp <- gap_long %>% + unite(ID_var, continent, country, sep = "_") %>% + unite(var_names, obs_type, year, sep = "_") +str(gap_temp) +``` + +``` output +tibble [5,112 × 3] (S3: tbl_df/tbl/data.frame) + $ ID_var : chr [1:5112] "Africa_Algeria" "Africa_Algeria" "Africa_Algeria" "Africa_Algeria" ... + $ var_names : chr [1:5112] "gdpPercap_1952" "gdpPercap_1957" "gdpPercap_1962" "gdpPercap_1967" ... + $ obs_values: num [1:5112] 2449 3014 2551 3247 4183 ... +``` + +Using `unite()` we now have a single ID variable which is a combination of +`continent`,`country`,and we have defined variable names. We're now ready to +pipe in `pivot_wider()` + + +``` r +gap_wide_new <- gap_long %>% + unite(ID_var, continent, country, sep = "_") %>% + unite(var_names, obs_type, year, sep = "_") %>% + pivot_wider(names_from = var_names, values_from = obs_values) +str(gap_wide_new) +``` + +``` output +tibble [142 × 37] (S3: tbl_df/tbl/data.frame) + $ ID_var : chr [1:142] "Africa_Algeria" "Africa_Angola" "Africa_Benin" "Africa_Botswana" ... + $ gdpPercap_1952: num [1:142] 2449 3521 1063 851 543 ... + $ gdpPercap_1957: num [1:142] 3014 3828 960 918 617 ... + $ gdpPercap_1962: num [1:142] 2551 4269 949 984 723 ... + $ gdpPercap_1967: num [1:142] 3247 5523 1036 1215 795 ... + $ gdpPercap_1972: num [1:142] 4183 5473 1086 2264 855 ... + $ gdpPercap_1977: num [1:142] 4910 3009 1029 3215 743 ... + $ gdpPercap_1982: num [1:142] 5745 2757 1278 4551 807 ... + $ gdpPercap_1987: num [1:142] 5681 2430 1226 6206 912 ... + $ gdpPercap_1992: num [1:142] 5023 2628 1191 7954 932 ... + $ gdpPercap_1997: num [1:142] 4797 2277 1233 8647 946 ... + $ gdpPercap_2002: num [1:142] 5288 2773 1373 11004 1038 ... + $ gdpPercap_2007: num [1:142] 6223 4797 1441 12570 1217 ... + $ lifeExp_1952 : num [1:142] 43.1 30 38.2 47.6 32 ... + $ lifeExp_1957 : num [1:142] 45.7 32 40.4 49.6 34.9 ... + $ lifeExp_1962 : num [1:142] 48.3 34 42.6 51.5 37.8 ... + $ lifeExp_1967 : num [1:142] 51.4 36 44.9 53.3 40.7 ... + $ lifeExp_1972 : num [1:142] 54.5 37.9 47 56 43.6 ... + $ lifeExp_1977 : num [1:142] 58 39.5 49.2 59.3 46.1 ... + $ lifeExp_1982 : num [1:142] 61.4 39.9 50.9 61.5 48.1 ... + $ lifeExp_1987 : num [1:142] 65.8 39.9 52.3 63.6 49.6 ... + $ lifeExp_1992 : num [1:142] 67.7 40.6 53.9 62.7 50.3 ... + $ lifeExp_1997 : num [1:142] 69.2 41 54.8 52.6 50.3 ... + $ lifeExp_2002 : num [1:142] 71 41 54.4 46.6 50.6 ... + $ lifeExp_2007 : num [1:142] 72.3 42.7 56.7 50.7 52.3 ... + $ pop_1952 : num [1:142] 9279525 4232095 1738315 442308 4469979 ... + $ pop_1957 : num [1:142] 10270856 4561361 1925173 474639 4713416 ... + $ pop_1962 : num [1:142] 11000948 4826015 2151895 512764 4919632 ... + $ pop_1967 : num [1:142] 12760499 5247469 2427334 553541 5127935 ... + $ pop_1972 : num [1:142] 14760787 5894858 2761407 619351 5433886 ... + $ pop_1977 : num [1:142] 17152804 6162675 3168267 781472 5889574 ... + $ pop_1982 : num [1:142] 20033753 7016384 3641603 970347 6634596 ... + $ pop_1987 : num [1:142] 23254956 7874230 4243788 1151184 7586551 ... + $ pop_1992 : num [1:142] 26298373 8735988 4981671 1342614 8878303 ... + $ pop_1997 : num [1:142] 29072015 9875024 6066080 1536536 10352843 ... + $ pop_2002 : num [1:142] 31287142 10866106 7026113 1630347 12251209 ... + $ pop_2007 : num [1:142] 33333216 12420476 8078314 1639131 14326203 ... +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Take this 1 step further and create a `gap_ludicrously_wide` format data by pivoting over countries, year and the 3 metrics? +**Hint** this new data frame should only have 5 rows. + +::::::::::::::: solution + +## Solution to Challenge 3 + + +``` r +gap_ludicrously_wide <- gap_long %>% + unite(var_names, obs_type, year, country, sep = "_") %>% + pivot_wider(names_from = var_names, values_from = obs_values) +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Now we have a great 'wide' format data frame, but the `ID_var` could be more +usable, let's separate it into 2 variables with `separate()` + + +``` r +gap_wide_betterID <- separate(gap_wide_new, ID_var, c("continent", "country"), sep="_") +gap_wide_betterID <- gap_long %>% + unite(ID_var, continent, country, sep = "_") %>% + unite(var_names, obs_type, year, sep = "_") %>% + pivot_wider(names_from = var_names, values_from = obs_values) %>% + separate(ID_var, c("continent","country"), sep = "_") +str(gap_wide_betterID) +``` + +``` output +tibble [142 × 38] (S3: tbl_df/tbl/data.frame) + $ continent : chr [1:142] "Africa" "Africa" "Africa" "Africa" ... + $ country : chr [1:142] "Algeria" "Angola" "Benin" "Botswana" ... + $ gdpPercap_1952: num [1:142] 2449 3521 1063 851 543 ... + $ gdpPercap_1957: num [1:142] 3014 3828 960 918 617 ... + $ gdpPercap_1962: num [1:142] 2551 4269 949 984 723 ... + $ gdpPercap_1967: num [1:142] 3247 5523 1036 1215 795 ... + $ gdpPercap_1972: num [1:142] 4183 5473 1086 2264 855 ... + $ gdpPercap_1977: num [1:142] 4910 3009 1029 3215 743 ... + $ gdpPercap_1982: num [1:142] 5745 2757 1278 4551 807 ... + $ gdpPercap_1987: num [1:142] 5681 2430 1226 6206 912 ... + $ gdpPercap_1992: num [1:142] 5023 2628 1191 7954 932 ... + $ gdpPercap_1997: num [1:142] 4797 2277 1233 8647 946 ... + $ gdpPercap_2002: num [1:142] 5288 2773 1373 11004 1038 ... + $ gdpPercap_2007: num [1:142] 6223 4797 1441 12570 1217 ... + $ lifeExp_1952 : num [1:142] 43.1 30 38.2 47.6 32 ... + $ lifeExp_1957 : num [1:142] 45.7 32 40.4 49.6 34.9 ... + $ lifeExp_1962 : num [1:142] 48.3 34 42.6 51.5 37.8 ... + $ lifeExp_1967 : num [1:142] 51.4 36 44.9 53.3 40.7 ... + $ lifeExp_1972 : num [1:142] 54.5 37.9 47 56 43.6 ... + $ lifeExp_1977 : num [1:142] 58 39.5 49.2 59.3 46.1 ... + $ lifeExp_1982 : num [1:142] 61.4 39.9 50.9 61.5 48.1 ... + $ lifeExp_1987 : num [1:142] 65.8 39.9 52.3 63.6 49.6 ... + $ lifeExp_1992 : num [1:142] 67.7 40.6 53.9 62.7 50.3 ... + $ lifeExp_1997 : num [1:142] 69.2 41 54.8 52.6 50.3 ... + $ lifeExp_2002 : num [1:142] 71 41 54.4 46.6 50.6 ... + $ lifeExp_2007 : num [1:142] 72.3 42.7 56.7 50.7 52.3 ... + $ pop_1952 : num [1:142] 9279525 4232095 1738315 442308 4469979 ... + $ pop_1957 : num [1:142] 10270856 4561361 1925173 474639 4713416 ... + $ pop_1962 : num [1:142] 11000948 4826015 2151895 512764 4919632 ... + $ pop_1967 : num [1:142] 12760499 5247469 2427334 553541 5127935 ... + $ pop_1972 : num [1:142] 14760787 5894858 2761407 619351 5433886 ... + $ pop_1977 : num [1:142] 17152804 6162675 3168267 781472 5889574 ... + $ pop_1982 : num [1:142] 20033753 7016384 3641603 970347 6634596 ... + $ pop_1987 : num [1:142] 23254956 7874230 4243788 1151184 7586551 ... + $ pop_1992 : num [1:142] 26298373 8735988 4981671 1342614 8878303 ... + $ pop_1997 : num [1:142] 29072015 9875024 6066080 1536536 10352843 ... + $ pop_2002 : num [1:142] 31287142 10866106 7026113 1630347 12251209 ... + $ pop_2007 : num [1:142] 33333216 12420476 8078314 1639131 14326203 ... +``` + +``` r +all.equal(gap_wide, gap_wide_betterID) +``` + +``` output +[1] "Attributes: < Component \"class\": Lengths (1, 3) differ (string compare on first 1) >" +[2] "Attributes: < Component \"class\": 1 string mismatch >" +``` + +There and back again! + +## Other great resources + +- [R for Data Science](https://r4ds.hadley.nz/) (online book) +- [Data Wrangling Cheat sheet](https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf) (pdf file) +- [Introduction to tidyr](https://cran.r-project.org/web/packages/tidyr/vignettes/tidy-data.html) (online documentation) +- [Data wrangling with R and RStudio](https://www.rstudio.com/resources/webinars/data-wrangling-with-r-and-rstudio/) (online video) + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use the `tidyr` package to change the layout of data frames. +- Use `pivot_longer()` to go from wide to longer layout. +- Use `pivot_wider()` to go from long to wider layout. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/14-knitr-markdown.md b/14-knitr-markdown.md new file mode 100644 index 000000000..aebe2b467 --- /dev/null +++ b/14-knitr-markdown.md @@ -0,0 +1,475 @@ +--- +title: Producing Reports With knitr +teaching: 60 +exercises: 15 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Understand the value of writing reproducible reports +- Learn how to recognise and compile the basic components of an R Markdown file +- Become familiar with R code chunks, and understand their purpose, structure and options +- Demonstrate the use of inline chunks for weaving R outputs into text blocks, for example when discussing the results of some calculations +- Be aware of alternative output formats to which an R Markdown file can be exported + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I integrate software and reports? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +## Data analysis reports + +Data analysts tend to write a lot of reports, describing their +analyses and results, for their collaborators or to document their +work for future reference. + +Many new users begin by first writing a single R script containing all of their +work, and then share the analysis by emailing the script and various graphs +as attachments. But this can be cumbersome, requiring a lengthy discussion to +explain which attachment was which result. + +Writing formal reports with Word or [LaTeX](https://www.latex-project.org/) +can simplify this process by incorporating both the analysis report and output graphs +into a single document. But tweaking formatting to make figures look correct +and fixing obnoxious page breaks can be tedious and lead to a lengthy "whack-a-mole" +game of fixing new mistakes resulting from a single formatting change. + +Creating a report as a web page (which is an html file) using R Markdown makes things easier. +The report can be one long stream, so tall figures that wouldn't ordinarily fit on +one page can be kept at full size and easier to read, since the reader can simply +keep scrolling. Additionally, the formatting of and R Markdown document is simple and easy to modify, allowing you to spend +more time on your analyses instead of writing reports. + +## Literate programming + +Ideally, such analysis reports are *reproducible* documents: If an +error is discovered, or if some additional subjects are added to the +data, you can just re-compile the report and get the new or corrected +results rather than having to reconstruct figures, paste them into +a Word document, and hand-edit various detailed results. + +The key R package here is [`knitr`](https://yihui.name/knitr/). It allows you +to create a document that is a mixture of text and chunks of +code. When the document is processed by `knitr`, chunks of code will +be executed, and graphs or other results will be inserted into the final document. + +This sort of idea has been called "literate programming". + +`knitr` allows you to mix basically any type of text with code from different programming languages, but we recommend that you use `R Markdown`, which mixes Markdown +with R. [Markdown](https://www.markdownguide.org/) is a light-weight mark-up language for creating web +pages. + +## Creating an R Markdown file + +Within RStudio, click File → New File → R Markdown and +you'll get a dialog box like this: + +![](fig/New_R_Markdown.png){alt='Screenshot of the New R Markdown file dialogue box in RStudio'} + +You can stick with the default (HTML output), but give it a title. + +## Basic components of R Markdown + +The initial chunk of text (header) contains instructions for R to specify what kind of document will be created, and the options chosen. You can use the header to give your document a title, author, date, and tell it what type of output you want +to produce. In this case, we're creating an html document. + +``` +--- +title: "Initial R Markdown document" +author: "Karl Broman" +date: "April 23, 2015" +output: html_document +--- +``` + +You can delete any of those fields if you don't want them +included. The double-quotes aren't strictly *necessary* in this case. +They're mostly needed if you want to include a colon in the title. + +RStudio creates the document with some example text to get you +started. Note below that there are chunks like + +
+```{r}
+summary(cars)
+```
+
+ +These are chunks of R code that will be executed by `knitr` and replaced +by their results. More on this later. + +## Markdown + +Markdown is a system for writing web pages by marking up the text much +as you would in an email rather than writing html code. The marked-up +text gets *converted* to html, replacing the marks with the proper +html code. + +For now, let's delete all of the stuff that's there and write a bit of +markdown. + +You make things **bold** using two asterisks, like this: `**bold**`, +and you make things *italics* by using underscores, like this: +`_italics_`. + +You can make a bulleted list by writing a list with hyphens or +asterisks with a space between the list and other text, like this: + +``` +A list: + +* bold with double-asterisks +* italics with underscores +* code-type font with backticks +``` + +or like this: + +``` +A second list: + +- bold with double-asterisks +- italics with underscores +- code-type font with backticks +``` + +Each will appear as: + +- bold with double-asterisks +- italics with underscores +- code-type font with backticks + +You can use whatever method you prefer, but *be consistent*. This maintains the +readability of your code. + +You can make a numbered list by just using numbers. You can even use the +same number over and over if you want: + +``` +1. bold with double-asterisks +1. italics with underscores +1. code-type font with backticks +``` + +This will appear as: + +1. bold with double-asterisks +2. italics with underscores +3. code-type font with backticks + +You can make section headers of different sizes by initiating a line +with some number of `#` symbols: + +``` +# Title +## Main section +### Sub-section +#### Sub-sub section +``` + +You *compile* the R Markdown document to an html webpage by clicking +the "Knit" button in the upper-left. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 1 + +Create a new R Markdown document. Delete all of the R code chunks +and write a bit of Markdown (some sections, some italicized +text, and an itemized list). + +Convert the document to a webpage. + +::::::::::::::: solution + +## Solution to Challenge 1 + +In RStudio, select File > New file > R Markdown... + +Delete the placeholder text and add the following: + +``` +# Introduction + +## Background on Data + +This report uses the *gapminder* dataset, which has columns that include: + +* country +* continent +* year +* lifeExp +* pop +* gdpPercap + +## Background on Methods + +``` + +Then click the 'Knit' button on the toolbar to generate an html document (webpage). + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## A bit more Markdown + +You can make a hyperlink like this: +`[Carpentries Home Page](https://carpentries.org/)`. + +You can include an image file like this: `![The Carpentries Logo](https://carpentries.org/assets/img/TheCarpentries.svg)` + +You can do subscripts (e.g., F~2~) with `F~2~` and superscripts (e.g., +F^2^) with `F^2^`. + +If you know how to write equations in +[LaTeX](https://www.latex-project.org/), you can use `$ $` and `$$ $$` to insert math equations, like +`$E = mc^2$` and + +``` +$$y = \mu + \sum_{i=1}^p \beta_i x_i + \epsilon$$ +``` + +You can review Markdown syntax by navigating to the +"Markdown Quick Reference" under the "Help" field in the +toolbar at the top of RStudio. + +## R code chunks + +The real power of Markdown comes from +mixing markdown with chunks of code. This is R Markdown. When +processed, the R code will be executed; if they produce figures, the +figures will be inserted in the final document. + +The main code chunks look like this: + +
+```{r load_data}
+gapminder <- read.csv("gapminder.csv")
+```
+
+ +That is, you place a chunk of R code between \`\`\`{r chunk\_name} +and \`\`\`. You should give each chunk +a unique name, as they will help you to fix errors and, if any graphs are +produced, the file names are based on the name of the code chunk that +produced them. You can create code chunks quickly in RStudio using the shortcuts +Ctrl\+Alt\+I on Windows and Linux, or Cmd\+Option\+I on Mac. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 2 + +Add code chunks to: + +- Load the ggplot2 package +- Read the gapminder data +- Create a plot + +::::::::::::::: solution + +## Solution to Challenge 2 + +
+```{r load-ggplot2}
+library("ggplot2")
+```
+
+ +
+```{r read-gapminder-data}
+gapminder <- read.csv("gapminder.csv")
+```
+
+ +
+```{r make-plot}
+plot(lifeExp ~ year, data = gapminder)
+```
+
+ +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## How things get compiled + +When you press the "Knit" button, the R Markdown document is +processed by [`knitr`](https://yihui.name/knitr) and a plain Markdown +document is produced (as well as, potentially, a set of figure files): the R code is executed +and replaced by both the input and the output; if figures are +produced, links to those figures are included. + +The Markdown and figure documents are then processed by the tool +[`pandoc`](https://pandoc.org/), which converts the Markdown file into an +html file, with the figures embedded. + + + +## Chunk options + +There are a variety of options to affect how the code chunks are +treated. Here are some examples: + +- Use `echo=FALSE` to avoid having the code itself shown. +- Use `results="hide"` to avoid having any results printed. +- Use `eval=FALSE` to have the code shown but not evaluated. +- Use `warning=FALSE` and `message=FALSE` to hide any warnings or + messages produced. +- Use `fig.height` and `fig.width` to control the size of the figures + produced (in inches). + +So you might write: + +
+```{r load_libraries, echo=FALSE, message=FALSE}
+library("dplyr")
+library("ggplot2")
+```
+
+ +Often there will be particular options that you'll want to use +repeatedly; for this, you can set *global* chunk options, like so: + +
+```{r global_options, echo=FALSE}
+knitr::opts_chunk$set(fig.path="Figs/", message=FALSE, warning=FALSE,
+                      echo=FALSE, results="hide", fig.width=11)
+```
+
+ +The `fig.path` option defines where the figures will be saved. The `/` +here is really important; without it, the figures would be saved in +the standard place but just with names that begin with `Figs`. + +If you have multiple R Markdown files in a common directory, you might +want to use `fig.path` to define separate prefixes for the figure file +names, like `fig.path="Figs/cleaning-"` and `fig.path="Figs/analysis-"`. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 3 + +Use chunk options to control the size of a figure and to hide the +code. + +::::::::::::::: solution + +## Solution to Challenge 3 + +
+```{r echo = FALSE, fig.width = 3}
+plot(faithful)
+```
+
+ +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +You can review all of the `R` chunk options by navigating to +the "R Markdown Cheat Sheet" under the "Cheatsheets" section +of the "Help" field in the toolbar at the top of RStudio. + +## Inline R code + +You can make *every* number in your report reproducible. Use +\`r and \` for an in-line code chunk, +like so: ``` `r round(some_value, 2)` ```. The code will be +executed and replaced with the *value* of the result. + +Don't let these in-line chunks get split across lines. + +Perhaps precede the paragraph with a larger code chunk that does +calculations and defines variables, with `include=FALSE` for that larger +chunk (which is the same as `echo=FALSE` and `results="hide"`). + +Rounding can produce differences in output in such situations. You may want +`2.0`, but `round(2.03, 1)` will give just `2`. + +The +[`myround`](https://github.com/kbroman/broman/blob/master/R/myround.R) +function in the [R/broman](https://github.com/kbroman/broman) package handles +this. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Challenge 4 + +Try out a bit of in-line R code. + +::::::::::::::: solution + +## Solution to Challenge 4 + +Here's some inline code to determine that 2 + 2 = ``4``. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Other output options + +You can also convert R Markdown to a PDF or a Word document. Click the +little triangle next to the "Knit" button to get a drop-down +menu. Or you could put `pdf_document` or `word_document` in the initial header +of the file. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Creating PDF documents + +Creating .pdf documents may require installation of some extra software. The R +package `tinytex` provides some tools to help make this process easier for R users. +With `tinytex` installed, run `tinytex::install_tinytex()` to install the required +software (you'll only need to do this once) and then when you knit to pdf `tinytex` +will automatically detect and install any additional LaTeX packages that are needed to +produce the pdf document. Visit the [tinytex website](https://yihui.org/tinytex/) +for more information. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: Visual markdown editing in RStudio + +RStudio versions 1.4 and later include visual markdown editing mode. +In visual editing mode, markdown expressions (like `**bold words**`) are +transformed to the formatted appearance (**bold words**) as you type. +This mode also includes a toolbar at the top with basic formatting buttons, +similar to what you might see in common word processing software programs. +You can turn visual editing on and off by pressing +the ![](fig/visual_mode_icon.png){alt='Icon for turning on and off the visual editing mode in RStudio, which looks like a pair of compasses'} +button in the top right corner of your R Markdown document. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Resources + +- [Knitr in a knutshell tutorial](https://kbroman.org/knitr_knutshell) +- [Dynamic Documents with R and knitr](https://www.amazon.com/exec/obidos/ASIN/1482203537/7210-20) (book) +- [R Markdown documentation](https://rmarkdown.rstudio.com) +- [R Markdown cheat sheet](https://www.rstudio.com/wp-content/uploads/2016/03/rmarkdown-cheatsheet-2.0.pdf) +- [Getting started with R Markdown](https://www.rstudio.com/resources/webinars/getting-started-with-r-markdown/) +- [R Markdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/) (book by Rstudio team) +- [Reproducible Reporting](https://www.rstudio.com/resources/webinars/reproducible-reporting/) +- [The Ecosystem of R Markdown](https://www.rstudio.com/resources/webinars/the-ecosystem-of-r-markdown/) +- [Introducing Bookdown](https://www.rstudio.com/resources/webinars/introducing-bookdown/) + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Mix reporting written in R Markdown with software written in R. +- Specify chunk options to control formatting. +- Use `knitr` to convert these documents into PDF and other formats. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/15-wrap-up.md b/15-wrap-up.md new file mode 100644 index 000000000..0ab7afb7a --- /dev/null +++ b/15-wrap-up.md @@ -0,0 +1,114 @@ +--- +title: Writing Good Software +teaching: 15 +exercises: 0 +source: Rmd +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Describe best practices for writing R and explain the justification for each. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I write software that other people can use? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Structure your project folder + +Keep your project folder structured, organized and tidy, by creating subfolders for your code files, manuals, data, binaries, output plots, etc. It can be done completely manually, or with the help of RStudio's `New Project` functionality, or a designated package, such as `ProjectTemplate`. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Tip: ProjectTemplate - a possible solution + +One way to automate the management of projects is to install the third-party package, `ProjectTemplate`. +This package will set up an ideal directory structure for project management. +This is very useful as it enables you to have your analysis pipeline/workflow organised and structured. +Together with the default RStudio project functionality and Git you will be able to keep track of your +work as well as be able to share your work with collaborators. + +1. Install `ProjectTemplate`. +2. Load the library +3. Initialise the project: + + +``` r +install.packages("ProjectTemplate") +library("ProjectTemplate") +create.project("../my_project_2", merge.strategy = "allow.non.conflict") +``` + +For more information on ProjectTemplate and its functionality visit the +home page [ProjectTemplate](https://projecttemplate.net/index.html) + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +## Make code readable + +The most important part of writing code is making it readable and understandable. +You want someone else to be able to pick up your code and be able to understand +what it does: more often than not this someone will be you 6 months down the line, +who will otherwise be cursing past-self. + +## Documentation: tell us what and why, not how + +When you first start out, your comments will often describe what a command does, +since you're still learning yourself and it can help to clarify concepts and +remind you later. However, these comments aren't particularly useful later on +when you don't remember what problem your code is trying to solve. Try to also +include comments that tell you *why* you're solving a problem, and *what* problem +that is. The *how* can come after that: it's an implementation detail you ideally +shouldn't have to worry about. + +## Keep your code modular + +Our recommendation is that you should separate your functions from your analysis +scripts, and store them in a separate file that you `source` when you open the R +session in your project. This approach is nice because it leaves you with an +uncluttered analysis script, and a repository of useful functions that can be +loaded into any analysis script in your project. It also lets you group related +functions together easily. + +## Break down problem into bite size pieces + +When you first start out, problem solving and function writing can be daunting +tasks, and hard to separate from code inexperience. Try to break down your +problem into digestible chunks and worry about the implementation details later: +keep breaking down the problem into smaller and smaller functions until you +reach a point where you can code a solution, and build back up from there. + +## Know that your code is doing the right thing + +Make sure to test your functions! + +## Don't repeat yourself + +Functions enable easy reuse within a project. If you see blocks of similar +lines of code through your project, those are usually candidates for being +moved into functions. + +If your calculations are performed through a series of functions, then the +project becomes more modular and easier to change. This is especially the case +for which a particular input always gives a particular output. + +## Remember to be stylish + +Apply consistent style to your code. + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Keep your project folder structured, organized and tidy. +- Document what and why, not how. +- Break programs into short single-purpose functions. +- Write re-runnable tests. +- Don't repeat yourself. +- Be consistent in naming, indentation, and other aspects of style. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..f19b80495 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,13 @@ +--- +title: "Contributor Code of Conduct" +--- + +As contributors and maintainers of this project, +we pledge to follow the [The Carpentries Code of Conduct][coc]. + +Instances of abusive, harassing, or otherwise unacceptable behavior +may be reported by following our [reporting guidelines][coc-reporting]. + + +[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html +[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..7632871ff --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,79 @@ +--- +title: "Licenses" +--- + +## Instructional Material + +All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry) +instructional material is made available under the [Creative Commons +Attribution license][cc-by-human]. The following is a human-readable summary of +(and not a substitute for) the [full legal text of the CC BY 4.0 +license][cc-by-legal]. + +You are free: + +- to **Share**---copy and redistribute the material in any medium or format +- to **Adapt**---remix, transform, and build upon the material + +for any purpose, even commercially. + +The licensor cannot revoke these freedoms as long as you follow the license +terms. + +Under the following terms: + +- **Attribution**---You must give appropriate credit (mentioning that your work + is derived from work that is Copyright (c) The Carpentries and, where + practical, linking to ), provide a [link to the + license][cc-by-human], and indicate if changes were made. You may do so in + any reasonable manner, but not in any way that suggests the licensor endorses + you or your use. + +- **No additional restrictions**---You may not apply legal terms or + technological measures that legally restrict others from doing anything the + license permits. With the understanding that: + +Notices: + +* You do not have to comply with the license for elements of the material in + the public domain or where your use is permitted by an applicable exception + or limitation. +* No warranties are given. The license may not give you all of the permissions + necessary for your intended use. For example, other rights such as publicity, + privacy, or moral rights may limit how you use the material. + +## Software + +Except where otherwise noted, the example programs and other software provided +by The Carpentries are made available under the [OSI][osi]-approved [MIT +license][mit-license]. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +## Trademark + +"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library +Carpentry" and their respective logos are registered trademarks of [Community +Initiatives][ci]. + +[cc-by-human]: https://creativecommons.org/licenses/by/4.0/ +[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode +[mit-license]: https://opensource.org/licenses/mit-license.html +[ci]: https://communityin.org/ +[osi]: https://opensource.org diff --git a/config.yaml b/config.yaml new file mode 100644 index 000000000..e94fdac68 --- /dev/null +++ b/config.yaml @@ -0,0 +1,95 @@ +#------------------------------------------------------------ +# Values for this lesson. +#------------------------------------------------------------ + +# Which carpentry is this (swc, dc, lc, or cp)? +# swc: Software Carpentry +# dc: Data Carpentry +# lc: Library Carpentry +# cp: Carpentries (to use for instructor training for instance) +# incubator: The Carpentries Incubator +carpentry: 'swc' + +# Overall title for pages. +title: 'R for Reproducible Scientific Analysis' + +# Date the lesson was created (YYYY-MM-DD, this is empty by default) +created: '2015-04-18' + +# Comma-separated list of keywords for the lesson +keywords: 'software, data, lesson, The Carpentries' + +# Life cycle stage of the lesson +# possible values: pre-alpha, alpha, beta, stable +life_cycle: 'stable' + +# License of the lesson materials (recommended CC-BY 4.0) +license: 'CC-BY 4.0' + +# Link to the source repository for this lesson +source: 'https://github.com/swcarpentry/r-novice-gapminder' + +# Default branch of your lesson +branch: 'main' + +# Who to contact if there are any issues +contact: 'team@carpentries.org' + +# Navigation ------------------------------------------------ +# +# Use the following menu items to specify the order of +# individual pages in each dropdown section. Leave blank to +# include all pages in the folder. +# +# Example ------------- +# +# episodes: +# - introduction.md +# - first-steps.md +# +# learners: +# - setup.md +# +# instructors: +# - instructor-notes.md +# +# profiles: +# - one-learner.md +# - another-learner.md + +# Order of episodes in your lesson +episodes: +- 01-rstudio-intro.Rmd +- 02-project-intro.Rmd +- 03-seeking-help.Rmd +- 04-data-structures-part1.Rmd +- 05-data-structures-part2.Rmd +- 06-data-subsetting.Rmd +- 07-control-flow.Rmd +- 08-plot-ggplot2.Rmd +- 09-vectorization.Rmd +- 10-functions.Rmd +- 11-writing-data.Rmd +- 12-dplyr.Rmd +- 13-tidyr.Rmd +- 14-knitr-markdown.Rmd +- 15-wrap-up.Rmd + +# Information for Learners +learners: + +# Information for Instructors +instructors: + +# Learner Profiles +profiles: + +# Customisation --------------------------------------------- +# +# This space below is where custom yaml items (e.g. pinning +# sandpaper and varnish versions) should live + + +url: 'https://swcarpentry.github.io/r-novice-gapminder' +analytics: carpentries +lang: en diff --git a/data/Owls.txt b/data/Owls.txt new file mode 100644 index 000000000..490a16eec --- /dev/null +++ b/data/Owls.txt @@ -0,0 +1,600 @@ +Nest FoodTreatment SexParent ArrivalTime SiblingNegotiation BroodSize NegPerChick +AutavauxTV Deprived Male 22.25 4 5 0.8 +AutavauxTV Satiated Male 22.38 0 5 0 +AutavauxTV Deprived Male 22.53 2 5 0.4 +AutavauxTV Deprived Male 22.56 2 5 0.4 +AutavauxTV Deprived Male 22.61 2 5 0.4 +AutavauxTV Deprived Male 22.65 2 5 0.4 +AutavauxTV Deprived Male 22.76 18 5 3.6 +AutavauxTV Satiated Female 22.9 4 5 0.8 +AutavauxTV Deprived Male 22.98 18 5 3.6 +AutavauxTV Satiated Female 23.07 0 5 0 +AutavauxTV Satiated Female 23.18 0 5 0 +AutavauxTV Deprived Female 23.28 3 5 0.6 +AutavauxTV Satiated Male 23.38 0 5 0 +AutavauxTV Deprived Male 23.43 3 5 0.6 +AutavauxTV Deprived Female 23.45 3 5 0.6 +AutavauxTV Deprived Male 23.68 6 5 1.2 +AutavauxTV Deprived Female 24 0 5 0 +AutavauxTV Satiated Male 24.21 4 5 0.8 +AutavauxTV Deprived Male 24.25 0 5 0 +AutavauxTV Deprived Male 24.58 7 5 1.4 +AutavauxTV Deprived Male 24.65 7 5 1.4 +AutavauxTV Satiated Male 24.95 0 5 0 +AutavauxTV Satiated Female 25.25 16 5 3.2 +AutavauxTV Satiated Male 25.75 7 5 1.4 +AutavauxTV Deprived Male 27.71 0 5 0 +AutavauxTV Deprived Female 27.85 7 5 1.4 +AutavauxTV Deprived Female 28.02 16 5 3.2 +AutavauxTV Deprived Male 28.82 5 5 1 +Bochet Satiated Female 22.81 3 4 0.75 +Bochet Satiated Male 23.2 2 4 0.5 +Bochet Deprived Male 23.22 13 4 3.25 +Bochet Deprived Female 23.23 13 4 3.25 +Bochet Deprived Male 23.33 22 4 5.5 +Bochet Satiated Male 23.36 2 4 0.5 +Bochet Satiated Female 23.4 2 4 0.5 +Bochet Satiated Male 23.45 2 4 0.5 +Bochet Deprived Male 23.46 22 4 5.5 +Bochet Deprived Female 23.5 12 4 3 +Bochet Satiated Female 23.51 0 4 0 +Bochet Deprived Female 23.53 12 4 3 +Bochet Deprived Male 23.78 12 4 3 +Bochet Satiated Male 23.88 0 4 0 +Bochet Satiated Female 23.95 0 4 0 +Bochet Satiated Female 24.35 0 4 0 +Bochet Satiated Female 24.45 0 4 0 +Bochet Deprived Male 26.3 0 4 0 +Bochet Deprived Male 26.43 0 4 0 +Bochet Satiated Male 27.1 0 4 0 +Bochet Satiated Male 27.33 0 4 0 +Bochet Deprived Male 27.55 0 4 0 +Bochet Satiated Male 27.98 0 4 0 +Champmartin Deprived Female 22.08 3 3 1 +Champmartin Deprived Female 22.36 0 3 0 +Champmartin Satiated Female 22.46 0 3 0 +Champmartin Deprived Female 22.62 10 3 3.33333333 +Champmartin Deprived Female 22.83 18 3 6 +Champmartin Deprived Female 22.98 18 3 6 +Champmartin Deprived Female 23.1 0 3 0 +Champmartin Deprived Female 23.15 0 3 0 +Champmartin Deprived Female 23.56 2 3 0.66666667 +Champmartin Deprived Female 23.73 2 3 0.66666667 +Champmartin Deprived Female 23.95 4 3 1.33333333 +Champmartin Satiated Female 24.1 0 3 0 +Champmartin Satiated Female 24.21 0 3 0 +Champmartin Deprived Female 24.53 3 3 1 +Champmartin Deprived Female 24.78 7 3 2.33333333 +Champmartin Deprived Female 24.93 7 3 2.33333333 +Champmartin Deprived Female 25.03 13 3 4.33333333 +Champmartin Deprived Female 25.28 16 3 5.33333333 +Champmartin Deprived Female 25.63 14 3 4.66666667 +Champmartin Satiated Female 25.71 0 3 0 +Champmartin Deprived Female 25.82 0 3 0 +Champmartin Deprived Female 26.6 0 3 0 +Champmartin Satiated Female 27.28 0 3 0 +Champmartin Satiated Female 27.4 0 3 0 +Champmartin Satiated Female 27.5 0 3 0 +Champmartin Deprived Female 27.66 0 3 0 +Champmartin Satiated Female 27.66 0 3 0 +Champmartin Satiated Female 27.91 0 3 0 +Champmartin Deprived Female 28.58 1 3 0.33333333 +Champmartin Deprived Female 29.23 3 3 1 +ChEsard Deprived Male 22.36 23 4 5.75 +ChEsard Deprived Male 22.55 19 4 4.75 +ChEsard Deprived Male 22.66 19 4 4.75 +ChEsard Deprived Male 23.13 14 4 3.5 +ChEsard Deprived Female 23.26 18 4 4.5 +ChEsard Deprived Male 23.33 18 4 4.5 +ChEsard Deprived Male 23.58 14 4 3.5 +ChEsard Deprived Male 23.68 14 4 3.5 +ChEsard Deprived Male 23.82 6 4 1.5 +ChEsard Deprived Male 23.93 6 4 1.5 +ChEsard Deprived Male 24.63 12 4 3 +ChEsard Deprived Female 24.66 12 4 3 +ChEsard Deprived Male 24.88 12 4 3 +ChEsard Satiated Female 25.38 19 4 4.75 +ChEsard Deprived Male 25.5 0 4 0 +ChEsard Deprived Male 25.95 17 4 4.25 +ChEsard Deprived Male 26.65 3 4 0.75 +ChEsard Deprived Male 26.85 11 4 2.75 +ChEsard Deprived Male 27.06 2 4 0.5 +ChEsard Satiated Male 27.66 6 4 1.5 +Chevroux Satiated Male 22.35 0 2 0 +Chevroux Satiated Male 23.2 0 2 0 +Chevroux Satiated Female 23.88 0 2 0 +Chevroux Satiated Male 24.01 0 2 0 +Chevroux Satiated Male 24.76 0 2 0 +Chevroux Deprived Male 25.31 17 2 8.5 +Chevroux Satiated Male 25.98 0 2 0 +Chevroux Deprived Male 26.05 5 2 2.5 +Chevroux Deprived Male 27.53 5 2 2.5 +Chevroux Deprived Male 28.31 7 2 3.5 +CorcellesFavres Satiated Male 22.76 2 3 0.66666667 +CorcellesFavres Satiated Male 24.11 9 3 3 +CorcellesFavres Deprived Female 25.15 7 3 2.33333333 +CorcellesFavres Satiated Female 25.38 2 3 0.66666667 +CorcellesFavres Satiated Male 25.63 4 3 1.33333333 +CorcellesFavres Satiated Male 26.03 9 3 3 +CorcellesFavres Satiated Male 26.3 5 3 1.66666667 +CorcellesFavres Satiated Male 26.73 6 3 2 +CorcellesFavres Satiated Male 28.43 3 3 1 +CorcellesFavres Satiated Male 28.86 7 3 2.33333333 +CorcellesFavres Deprived Female 28.98 5 3 1.66666667 +CorcellesFavres Satiated Male 29.11 20 3 6.66666667 +Etrabloz Deprived Male 22.01 4 5 0.8 +Etrabloz Deprived Female 22.15 4 5 0.8 +Etrabloz Deprived Male 22.26 14 5 2.8 +Etrabloz Satiated Female 22.46 0 5 0 +Etrabloz Satiated Female 22.51 0 5 0 +Etrabloz Deprived Female 22.7 9 5 1.8 +Etrabloz Deprived Male 22.85 14 5 2.8 +Etrabloz Deprived Male 23.13 6 5 1.2 +Etrabloz Satiated Male 23.3 2 5 0.4 +Etrabloz Deprived Male 23.31 8 5 1.6 +Etrabloz Deprived Female 23.7 2 5 0.4 +Etrabloz Satiated Male 23.73 0 5 0 +Etrabloz Deprived Male 23.76 5 5 1 +Etrabloz Deprived Female 23.81 5 5 1 +Etrabloz Satiated Male 24.05 0 5 0 +Etrabloz Satiated Female 24.38 0 5 0 +Etrabloz Satiated Female 24.43 0 5 0 +Etrabloz Satiated Female 24.58 0 5 0 +Etrabloz Deprived Female 24.65 0 5 0 +Etrabloz Satiated Female 25.05 0 5 0 +Etrabloz Satiated Female 25.61 0 5 0 +Etrabloz Deprived Female 25.61 1 5 0.2 +Etrabloz Satiated Male 26.28 0 5 0 +Etrabloz Deprived Female 26.33 5 5 1 +Etrabloz Deprived Female 26.48 5 5 1 +Etrabloz Deprived Female 26.85 1 5 0.2 +Etrabloz Deprived Female 27.5 10 5 2 +Etrabloz Deprived Male 27.55 8 5 1.6 +Etrabloz Satiated Female 28.26 2 5 0.4 +Etrabloz Deprived Male 28.35 10 5 2 +Etrabloz Deprived Male 28.7 2 5 0.4 +Etrabloz Deprived Male 28.81 13 5 2.6 +Etrabloz Deprived Male 28.9 13 5 2.6 +Etrabloz Deprived Male 29.25 13 5 2.6 +Forel Satiated Male 23.25 0 4 0 +Forel Deprived Male 23.92 1 4 0.25 +Forel Satiated Male 24.26 0 4 0 +Forel Satiated Male 24.3 0 4 0 +Franex Satiated Male 22.36 0 4 0 +Franex Satiated Male 22.45 0 4 0 +Franex Deprived Female 22.66 19 4 4.75 +Franex Deprived Male 22.68 19 4 4.75 +Franex Deprived Male 22.75 19 4 4.75 +Franex Deprived Female 22.76 8 4 2 +Franex Deprived Female 23.05 9 4 2.25 +Franex Deprived Male 23.48 1 4 0.25 +Franex Deprived Male 23.65 4 4 1 +Franex Deprived Male 23.8 3 4 0.75 +Franex Deprived Male 23.9 3 4 0.75 +Franex Deprived Male 24.05 6 4 1.5 +Franex Deprived Female 24.08 6 4 1.5 +Franex Deprived Male 24.25 6 4 1.5 +Franex Satiated Female 24.58 0 4 0 +Franex Satiated Female 24.68 0 4 0 +Franex Satiated Male 24.73 0 4 0 +Franex Satiated Male 25.11 3 4 0.75 +Franex Deprived Male 25.26 0 4 0 +Franex Deprived Male 26.36 4 4 1 +Franex Deprived Male 26.6 4 4 1 +Franex Deprived Male 26.71 4 4 1 +Franex Deprived Male 26.95 14 4 3.5 +Franex Satiated Male 27.1 5 4 1.25 +Franex Deprived Female 27.25 8 4 2 +Franex Deprived Male 27.38 16 4 4 +GDLV Deprived Male 22.46 6 5 1.2 +GDLV Deprived Female 22.83 9 5 1.8 +GDLV Satiated Male 22.91 1 5 0.2 +GDLV Deprived Male 23.08 11 5 2.2 +GDLV Deprived Male 23.75 11 5 2.2 +GDLV Deprived Male 23.91 12 5 2.4 +GDLV Deprived Male 25.26 12 5 2.4 +GDLV Satiated Male 25.56 2 5 0.4 +GDLV Deprived Female 26.85 9 5 1.8 +GDLV Satiated Male 28.78 0 5 0 +Gletterens Deprived Female 23.15 16 2 8 +Gletterens Deprived Female 23.25 16 2 8 +Gletterens Satiated Female 23.8 3 2 1.5 +Gletterens Deprived Female 24.05 0 2 0 +Gletterens Deprived Female 24.53 0 2 0 +Gletterens Deprived Male 24.55 0 2 0 +Gletterens Satiated Male 24.81 0 2 0 +Gletterens Deprived Female 24.85 5 2 2.5 +Gletterens Satiated Female 25.1 9 2 4.5 +Gletterens Deprived Female 25.8 10 2 5 +Gletterens Deprived Male 26.3 3 2 1.5 +Gletterens Deprived Male 27.23 0 2 0 +Gletterens Satiated Female 27.4 0 2 0 +Gletterens Deprived Male 27.61 0 2 0 +Gletterens Deprived Male 28.78 2 2 1 +Henniez Deprived Female 22.51 6 2 3 +Henniez Deprived Female 22.63 6 2 3 +Henniez Satiated Female 22.68 2 2 1 +Henniez Satiated Female 22.76 17 2 8.5 +Henniez Deprived Female 22.91 3 2 1.5 +Henniez Satiated Female 23.06 0 2 0 +Henniez Satiated Female 23.28 0 2 0 +Henniez Deprived Female 23.81 0 2 0 +Henniez Satiated Female 23.96 0 2 0 +Henniez Deprived Female 25.88 0 2 0 +Henniez Deprived Female 26.78 0 2 0 +Henniez Deprived Female 27.63 0 2 0 +Henniez Satiated Female 28.26 0 2 0 +Jeuss Satiated Male 22.66 3 5 0.6 +Jeuss Deprived Female 23.11 9 5 1.8 +Jeuss Satiated Male 23.16 0 5 0 +Jeuss Satiated Female 23.41 0 5 0 +Jeuss Deprived Male 25.58 12 5 2.4 +Jeuss Satiated Male 25.9 0 5 0 +Jeuss Deprived Male 25.93 2 5 0.4 +Jeuss Deprived Female 26.16 11 5 2.2 +Jeuss Deprived Male 26.33 5 5 1 +Jeuss Deprived Male 26.56 3 5 0.6 +Jeuss Satiated Female 26.6 0 5 0 +Jeuss Deprived Female 26.75 3 5 0.6 +Jeuss Deprived Male 26.83 3 5 0.6 +Jeuss Satiated Female 26.98 0 5 0 +Jeuss Satiated Male 27.48 0 5 0 +Jeuss Deprived Female 27.51 0 5 0 +Jeuss Satiated Female 28 0 5 0 +Jeuss Satiated Male 28.8 0 5 0 +Jeuss Deprived Male 28.98 2 5 0.4 +LesPlanches Satiated Male 21.78 0 3 0 +LesPlanches Satiated Male 21.81 0 3 0 +LesPlanches Deprived Male 22.3 3 3 1 +LesPlanches Satiated Male 22.31 0 3 0 +LesPlanches Satiated Male 22.51 10 3 3.33333333 +LesPlanches Deprived Male 22.63 10 3 3.33333333 +LesPlanches Deprived Male 23.06 10 3 3.33333333 +LesPlanches Satiated Male 23.38 0 3 0 +LesPlanches Satiated Male 23.41 0 3 0 +LesPlanches Satiated Male 23.68 11 3 3.66666667 +LesPlanches Deprived Male 24.03 0 3 0 +LesPlanches Satiated Male 24.43 0 3 0 +LesPlanches Deprived Male 26.55 0 3 0 +LesPlanches Deprived Female 26.76 0 3 0 +LesPlanches Deprived Male 27.45 0 3 0 +LesPlanches Deprived Male 27.6 11 3 3.66666667 +LesPlanches Deprived Male 28.26 6 3 2 +Lucens Satiated Male 22.36 9 4 2.25 +Lucens Deprived Female 22.38 23 4 5.75 +Lucens Deprived Male 22.68 15 4 3.75 +Lucens Satiated Male 22.76 2 4 0.5 +Lucens Deprived Male 22.81 12 4 3 +Lucens Deprived Male 22.9 12 4 3 +Lucens Deprived Male 22.98 12 4 3 +Lucens Satiated Female 23.03 0 4 0 +Lucens Deprived Female 23.38 0 4 0 +Lucens Deprived Female 23.45 0 4 0 +Lucens Deprived Female 23.51 14 4 3.5 +Lucens Deprived Male 23.56 14 4 3.5 +Lucens Deprived Female 23.6 14 4 3.5 +Lucens Deprived Male 24.25 2 4 0.5 +Lucens Satiated Male 25.05 13 4 3.25 +Lucens Deprived Female 25.1 0 4 0 +Lucens Deprived Female 25.36 1 4 0.25 +Lucens Satiated Male 26.2 0 4 0 +Lucens Deprived Male 26.5 4 4 1 +Lucens Deprived Female 26.61 8 4 2 +Lucens Deprived Male 26.81 1 4 0.25 +Lucens Satiated Male 26.85 0 4 0 +Lucens Deprived Male 27.08 4 4 1 +Lucens Satiated Female 27.16 0 4 0 +Lucens Deprived Female 27.53 5 4 1.25 +Lucens Deprived Female 28.03 8 4 2 +Lucens Satiated Female 28.13 9 4 2.25 +Lucens Satiated Male 28.26 7 4 1.75 +Lucens Deprived Male 28.4 7 4 1.75 +Lully Deprived Male 22.31 16 4 4 +Lully Deprived Female 22.51 13 4 3.25 +Lully Deprived Male 22.55 13 4 3.25 +Lully Deprived Male 22.98 15 4 3.75 +Lully Deprived Male 23.01 14 4 3.5 +Lully Deprived Male 23.15 14 4 3.5 +Lully Satiated Female 23.25 6 4 1.5 +Lully Deprived Female 23.63 15 4 3.75 +Lully Deprived Male 23.66 15 4 3.75 +Lully Satiated Male 23.7 6 4 1.5 +Lully Deprived Female 24.4 0 4 0 +Lully Satiated Male 24.85 1 4 0.25 +Lully Deprived Female 25.13 0 4 0 +Lully Satiated Male 26.78 9 4 2.25 +Lully Satiated Male 26.93 9 4 2.25 +Lully Satiated Male 27.31 3 4 0.75 +Lully Deprived Male 28.58 2 4 0.5 +Marnand Deprived Male 22.28 12 4 3 +Marnand Satiated Female 22.53 6 4 1.5 +Marnand Satiated Male 22.65 6 4 1.5 +Marnand Deprived Male 22.73 13 4 3.25 +Marnand Deprived Female 22.98 28 4 7 +Marnand Satiated Male 23.35 0 4 0 +Marnand Deprived Female 23.4 6 4 1.5 +Marnand Deprived Male 23.86 0 4 0 +Marnand Satiated Male 24.23 3 4 0.75 +Marnand Satiated Female 24.31 2 4 0.5 +Marnand Deprived Male 24.41 4 4 1 +Marnand Deprived Female 24.48 4 4 1 +Marnand Satiated Female 24.58 8 4 2 +Marnand Satiated Male 24.63 8 4 2 +Marnand Deprived Female 25.13 13 4 3.25 +Marnand Deprived Male 25.53 7 4 1.75 +Marnand Deprived Male 25.58 4 4 1 +Marnand Satiated Female 25.63 0 4 0 +Marnand Satiated Female 25.68 0 4 0 +Marnand Satiated Male 25.86 12 4 3 +Marnand Deprived Male 25.96 4 4 1 +Marnand Deprived Male 26.06 17 4 4.25 +Marnand Satiated Male 26.38 7 4 1.75 +Marnand Deprived Male 26.53 5 4 1.25 +Marnand Satiated Male 26.76 1 4 0.25 +Marnand Deprived Male 27.38 0 4 0 +Marnand Deprived Male 27.46 0 4 0 +Montet Satiated Male 22.7 6 5 1.2 +Montet Deprived Male 22.95 15 5 3 +Montet Deprived Male 23.11 17 5 3.4 +Montet Deprived Male 23.33 10 5 2 +Montet Satiated Female 23.55 2 5 0.4 +Montet Deprived Male 23.6 15 5 3 +Montet Satiated Male 23.63 2 5 0.4 +Montet Deprived Male 23.81 10 5 2 +Montet Satiated Male 24.05 0 5 0 +Montet Deprived Male 24.06 7 5 1.4 +Montet Deprived Male 24.08 7 5 1.4 +Montet Deprived Male 24.2 7 5 1.4 +Montet Deprived Male 24.3 15 5 3 +Montet Satiated Male 24.35 5 5 1 +Montet Satiated Male 24.43 5 5 1 +Montet Deprived Male 24.48 15 5 3 +Montet Deprived Male 24.61 19 5 3.8 +Montet Satiated Male 24.66 0 5 0 +Montet Deprived Male 24.7 19 5 3.8 +Montet Satiated Male 24.81 12 5 2.4 +Montet Deprived Male 24.85 10 5 2 +Montet Satiated Male 24.9 12 5 2.4 +Montet Deprived Male 24.96 10 5 2 +Montet Deprived Male 25.03 20 5 4 +Montet Deprived Male 25.1 20 5 4 +Montet Satiated Female 25.36 7 5 1.4 +Montet Satiated Male 25.38 7 5 1.4 +Montet Satiated Male 25.55 22 5 4.4 +Montet Satiated Male 25.73 22 5 4.4 +Montet Deprived Male 25.9 4 5 0.8 +Montet Deprived Female 26.55 14 5 2.8 +Montet Deprived Male 26.83 4 5 0.8 +Montet Satiated Female 26.91 0 5 0 +Montet Satiated Male 26.93 0 5 0 +Montet Deprived Male 27.23 2 5 0.4 +Montet Deprived Male 27.43 0 5 0 +Montet Deprived Male 27.56 12 5 2.4 +Montet Deprived Male 27.83 4 5 0.8 +Montet Satiated Female 28.3 2 5 0.4 +Montet Satiated Male 28.38 2 5 0.4 +Montet Satiated Female 28.86 1 5 0.2 +Murist Deprived Female 22.23 3 4 0.75 +Murist Satiated Female 22.26 24 4 6 +Murist Deprived Male 22.5 24 4 6 +Murist Deprived Male 22.51 14 4 3.5 +Murist Deprived Male 22.58 14 4 3.5 +Murist Satiated Male 22.6 14 4 3.5 +Murist Deprived Male 22.61 14 4 3.5 +Murist Deprived Female 22.63 14 4 3.5 +Murist Deprived Male 22.66 14 4 3.5 +Murist Satiated Male 22.78 14 4 3.5 +Murist Satiated Male 22.86 14 4 3.5 +Murist Satiated Female 22.93 14 4 3.5 +Murist Deprived Male 23.1 0 4 0 +Murist Satiated Male 23.4 0 4 0 +Murist Deprived Female 23.78 0 4 0 +Murist Deprived Female 23.8 0 4 0 +Murist Satiated Male 25.7 3 4 0.75 +Murist Satiated Male 25.83 0 4 0 +Murist Deprived Male 26.23 6 4 1.5 +Murist Satiated Male 26.41 17 4 4.25 +Murist Deprived Male 27.25 5 4 1.25 +Murist Satiated Male 27.53 0 4 0 +Murist Satiated Male 27.73 0 4 0 +Murist Deprived Male 27.96 3 4 0.75 +Oleyes Satiated Female 21.76 11 5 2.2 +Oleyes Satiated Female 22.13 17 5 3.4 +Oleyes Satiated Female 22.28 17 5 3.4 +Oleyes Deprived Female 22.38 2 5 0.4 +Oleyes Satiated Male 22.4 12 5 2.4 +Oleyes Satiated Female 22.61 12 5 2.4 +Oleyes Satiated Male 22.73 13 5 2.6 +Oleyes Satiated Female 22.85 10 5 2 +Oleyes Deprived Female 22.96 16 5 3.2 +Oleyes Satiated Male 23.08 15 5 3 +Oleyes Deprived Male 23.1 12 5 2.4 +Oleyes Deprived Male 23.43 11 5 2.2 +Oleyes Satiated Male 23.65 0 5 0 +Oleyes Satiated Female 23.65 0 5 0 +Oleyes Deprived Male 23.7 7 5 1.4 +Oleyes Deprived Female 23.83 6 5 1.2 +Oleyes Deprived Male 23.96 6 5 1.2 +Oleyes Satiated Male 24.11 0 5 0 +Oleyes Satiated Female 24.13 0 5 0 +Oleyes Deprived Male 24.2 5 5 1 +Oleyes Deprived Male 24.41 5 5 1 +Oleyes Deprived Male 24.56 7 5 1.4 +Oleyes Satiated Female 24.73 2 5 0.4 +Oleyes Satiated Male 24.9 32 5 6.4 +Oleyes Deprived Male 24.93 6 5 1.2 +Oleyes Satiated Male 25.08 32 5 6.4 +Oleyes Satiated Female 25.16 5 5 1 +Oleyes Deprived Female 25.2 7 5 1.4 +Oleyes Deprived Male 25.2 7 5 1.4 +Oleyes Satiated Male 25.45 5 5 1 +Oleyes Satiated Female 25.51 0 5 0 +Oleyes Deprived Male 25.68 3 5 0.6 +Oleyes Satiated Male 25.76 7 5 1.4 +Oleyes Deprived Female 25.8 14 5 2.8 +Oleyes Satiated Female 26 6 5 1.2 +Oleyes Satiated Male 26 6 5 1.2 +Oleyes Deprived Male 26 14 5 2.8 +Oleyes Deprived Male 26.03 0 5 0 +Oleyes Satiated Female 26.1 0 5 0 +Oleyes Satiated Male 26.28 13 5 2.6 +Oleyes Satiated Female 26.4 13 5 2.6 +Oleyes Satiated Male 26.55 0 5 0 +Oleyes Deprived Female 26.63 4 5 0.8 +Oleyes Deprived Male 26.75 4 5 0.8 +Oleyes Satiated Male 26.8 0 5 0 +Oleyes Satiated Male 26.98 0 5 0 +Oleyes Deprived Male 27.13 10 5 2 +Oleyes Deprived Female 27.31 10 5 2 +Oleyes Deprived Female 27.83 6 5 1.2 +Oleyes Deprived Male 28.03 2 5 0.4 +Oleyes Satiated Female 28.25 0 5 0 +Oleyes Deprived Female 28.86 0 5 0 +Payerne Satiated Male 22.08 6 5 1.2 +Payerne Satiated Female 22.15 6 5 1.2 +Payerne Satiated Female 22.61 8 5 1.6 +Payerne Satiated Male 22.63 8 5 1.6 +Payerne Satiated Female 22.71 8 5 1.6 +Payerne Deprived Male 22.78 8 5 1.6 +Payerne Satiated Male 22.88 7 5 1.4 +Payerne Deprived Female 23.01 15 5 3 +Payerne Satiated Male 23.03 8 5 1.6 +Payerne Satiated Female 23.1 8 5 1.6 +Payerne Satiated Female 23.35 0 5 0 +Payerne Satiated Male 23.43 0 5 0 +Payerne Satiated Male 23.68 1 5 0.2 +Payerne Satiated Male 24.1 8 5 1.6 +Payerne Satiated Male 24.35 5 5 1 +Payerne Satiated Male 24.48 5 5 1 +Payerne Satiated Male 25 7 5 1.4 +Payerne Deprived Male 25.05 10 5 2 +Payerne Deprived Male 25.26 14 5 2.8 +Payerne Satiated Female 25.35 0 5 0 +Payerne Deprived Female 25.36 14 5 2.8 +Payerne Satiated Male 25.51 0 5 0 +Payerne Satiated Male 25.85 0 5 0 +Payerne Satiated Male 26.31 0 5 0 +Payerne Satiated Male 27.53 0 5 0 +Rueyes Deprived Female 22.01 6 4 1.5 +Rueyes Satiated Female 22.06 0 4 0 +Rueyes Deprived Male 22.26 10 4 2.5 +Rueyes Satiated Male 22.35 18 4 4.5 +Rueyes Satiated Male 22.38 18 4 4.5 +Rueyes Satiated Male 22.48 18 4 4.5 +Rueyes Satiated Male 22.5 18 4 4.5 +Rueyes Satiated Male 22.58 11 4 2.75 +Rueyes Deprived Male 22.7 7 4 1.75 +Rueyes Satiated Male 22.95 11 4 2.75 +Rueyes Satiated Male 23.78 9 4 2.25 +Rueyes Deprived Male 24.05 6 4 1.5 +Rueyes Deprived Male 24.31 6 4 1.5 +Rueyes Satiated Female 25.06 0 4 0 +Rueyes Satiated Male 25.33 0 4 0 +Rueyes Deprived Male 25.35 1 4 0.25 +Rueyes Deprived Female 28.2 7 4 1.75 +Seiry Satiated Female 22.13 1 6 0.16666667 +Seiry Deprived Female 22.43 16 6 2.66666667 +Seiry Deprived Male 22.46 16 6 2.66666667 +Seiry Satiated Female 22.83 2 6 0.33333333 +Seiry Satiated Male 22.85 2 6 0.33333333 +Seiry Satiated Female 23.03 26 6 4.33333333 +Seiry Satiated Male 23.35 1 6 0.16666667 +Seiry Satiated Male 23.55 8 6 1.33333333 +Seiry Satiated Female 23.6 8 6 1.33333333 +Seiry Deprived Male 23.81 13 6 2.16666667 +Seiry Satiated Male 24.01 2 6 0.33333333 +Seiry Deprived Female 24.23 15 6 2.5 +Seiry Deprived Male 24.43 8 6 1.33333333 +Seiry Satiated Female 24.45 0 6 0 +Seiry Satiated Male 24.55 10 6 1.66666667 +Seiry Deprived Male 24.93 6 6 1 +Seiry Satiated Male 24.95 7 6 1.16666667 +Seiry Satiated Male 25.8 2 6 0.33333333 +Seiry Satiated Male 26 2 6 0.33333333 +Seiry Deprived Male 26.01 17 6 2.83333333 +Seiry Satiated Male 26.16 11 6 1.83333333 +Seiry Deprived Male 26.33 13 6 2.16666667 +Seiry Deprived Female 27.1 4 6 0.66666667 +Seiry Satiated Male 27.11 0 6 0 +Seiry Satiated Female 27.4 6 6 1 +Seiry Satiated Female 27.63 26 6 4.33333333 +Sevaz Deprived Male 22.86 6 1 6 +Sevaz Satiated Female 23.85 3 1 3 +Sevaz Satiated Male 26 6 1 6 +Sevaz Satiated Male 27.96 1 1 1 +StAubin Satiated Female 22.51 2 4 0.5 +StAubin Satiated Male 22.51 2 4 0.5 +StAubin Deprived Female 22.55 12 4 3 +StAubin Satiated Female 23.03 0 4 0 +StAubin Deprived Female 23.03 1 4 0.25 +StAubin Deprived Male 23.3 2 4 0.5 +StAubin Satiated Female 23.35 6 4 1.5 +StAubin Satiated Female 23.61 1 4 0.25 +StAubin Deprived Female 23.66 9 4 2.25 +StAubin Deprived Female 23.85 8 4 2 +StAubin Deprived Female 24.06 6 4 1.5 +StAubin Satiated Female 24.38 0 4 0 +StAubin Deprived Female 24.38 0 4 0 +StAubin Deprived Female 25.11 4 4 1 +StAubin Satiated Female 25.3 0 4 0 +StAubin Deprived Female 25.36 3 4 0.75 +StAubin Satiated Female 26.16 5 4 1.25 +StAubin Satiated Female 26.83 0 4 0 +StAubin Deprived Male 27.25 0 4 0 +StAubin Deprived Female 27.43 1 4 0.25 +StAubin Satiated Female 27.43 9 4 2.25 +StAubin Deprived Female 27.71 12 4 3 +StAubin Deprived Female 27.91 8 4 2 +Trey Deprived Female 22.05 16 5 3.2 +Trey Satiated Female 22.43 1 5 0.2 +Trey Satiated Male 22.73 12 5 2.4 +Trey Satiated Female 22.9 25 5 5 +Trey Satiated Male 23.2 16 5 3.2 +Trey Satiated Female 23.45 20 5 4 +Trey Satiated Male 23.73 23 5 4.6 +Trey Satiated Female 24.15 2 5 0.4 +Trey Satiated Female 24.36 11 5 2.2 +Trey Satiated Female 24.5 11 5 2.2 +Trey Satiated Male 24.6 3 5 0.6 +Trey Satiated Male 24.93 18 5 3.6 +Trey Satiated Female 25.28 5 5 1 +Trey Satiated Female 25.8 1 5 0.2 +Trey Satiated Male 25.86 1 5 0.2 +Trey Satiated Female 26.1 8 5 1.6 +Trey Satiated Male 27.66 0 5 0 +Trey Satiated Female 27.76 11 5 2.2 +Trey Satiated Female 27.93 11 5 2.2 +Yvonnand Satiated Female 21.71 10 7 1.42857143 +Yvonnand Satiated Female 21.73 10 7 1.42857143 +Yvonnand Satiated Female 21.91 17 7 2.42857143 +Yvonnand Satiated Male 21.93 17 7 2.42857143 +Yvonnand Satiated Female 21.95 17 7 2.42857143 +Yvonnand Deprived Male 21.96 6 7 0.85714286 +Yvonnand Deprived Female 22.18 19 7 2.71428571 +Yvonnand Satiated Male 22.28 4 7 0.57142857 +Yvonnand Deprived Male 22.3 31 7 4.42857143 +Yvonnand Deprived Male 22.5 31 7 4.42857143 +Yvonnand Satiated Male 22.56 10 7 1.42857143 +Yvonnand Deprived Female 22.6 23 7 3.28571429 +Yvonnand Deprived Male 22.6 23 7 3.28571429 +Yvonnand Deprived Male 22.9 15 7 2.14285714 +Yvonnand Satiated Male 23.25 0 7 0 +Yvonnand Satiated Female 23.46 6 7 0.85714286 +Yvonnand Satiated Female 23.53 1 7 0.14285714 +Yvonnand Satiated Female 23.63 1 7 0.14285714 +Yvonnand Deprived Male 24 9 7 1.28571429 +Yvonnand Deprived Male 24.31 6 7 0.85714286 +Yvonnand Deprived Male 24.56 8 7 1.14285714 +Yvonnand Deprived Male 24.73 10 7 1.42857143 +Yvonnand Satiated Male 25.25 4 7 0.57142857 +Yvonnand Satiated Female 25.41 11 7 1.57142857 +Yvonnand Satiated Female 25.56 9 7 1.28571429 +Yvonnand Satiated Female 25.76 14 7 2 +Yvonnand Deprived Male 26.15 13 7 1.85714286 +Yvonnand Deprived Male 26.76 22 7 3.14285714 +Yvonnand Deprived Male 27.23 7 7 1 +Yvonnand Deprived Female 27.25 7 7 1 +Yvonnand Deprived Male 28.45 5 7 0.71428571 +Yvonnand Deprived Female 28.86 15 7 2.14285714 +Yvonnand Deprived Male 29.21 10 7 1.42857143 +Yvonnand Satiated Female 29.23 0 7 0 diff --git a/data/feline-data.csv b/data/feline-data.csv new file mode 100644 index 000000000..df1620802 --- /dev/null +++ b/data/feline-data.csv @@ -0,0 +1,4 @@ +"coat","weight","likes_string" +"calico",2.1,1 +"black",5,0 +"tabby",3.2,1 diff --git a/data/feline-data_v2.csv b/data/feline-data_v2.csv new file mode 100644 index 000000000..76d324ebe --- /dev/null +++ b/data/feline-data_v2.csv @@ -0,0 +1,5 @@ +coat,weight,likes_string +calico,2.1,1 +black,5,0 +tabby,3.2,1 +tabby,2.3 or 2.4,1 diff --git a/data/gapminder-FiveYearData.csv b/data/gapminder-FiveYearData.csv new file mode 100644 index 000000000..661ddefc6 --- /dev/null +++ b/data/gapminder-FiveYearData.csv @@ -0,0 +1,1705 @@ +country,year,pop,continent,lifeExp,gdpPercap +Afghanistan,1952,8425333,Asia,28.801,779.4453145 +Afghanistan,1957,9240934,Asia,30.332,820.8530296 +Afghanistan,1962,10267083,Asia,31.997,853.10071 +Afghanistan,1967,11537966,Asia,34.02,836.1971382 +Afghanistan,1972,13079460,Asia,36.088,739.9811058 +Afghanistan,1977,14880372,Asia,38.438,786.11336 +Afghanistan,1982,12881816,Asia,39.854,978.0114388 +Afghanistan,1987,13867957,Asia,40.822,852.3959448 +Afghanistan,1992,16317921,Asia,41.674,649.3413952 +Afghanistan,1997,22227415,Asia,41.763,635.341351 +Afghanistan,2002,25268405,Asia,42.129,726.7340548 +Afghanistan,2007,31889923,Asia,43.828,974.5803384 +Albania,1952,1282697,Europe,55.23,1601.056136 +Albania,1957,1476505,Europe,59.28,1942.284244 +Albania,1962,1728137,Europe,64.82,2312.888958 +Albania,1967,1984060,Europe,66.22,2760.196931 +Albania,1972,2263554,Europe,67.69,3313.422188 +Albania,1977,2509048,Europe,68.93,3533.00391 +Albania,1982,2780097,Europe,70.42,3630.880722 +Albania,1987,3075321,Europe,72,3738.932735 +Albania,1992,3326498,Europe,71.581,2497.437901 +Albania,1997,3428038,Europe,72.95,3193.054604 +Albania,2002,3508512,Europe,75.651,4604.211737 +Albania,2007,3600523,Europe,76.423,5937.029526 +Algeria,1952,9279525,Africa,43.077,2449.008185 +Algeria,1957,10270856,Africa,45.685,3013.976023 +Algeria,1962,11000948,Africa,48.303,2550.81688 +Algeria,1967,12760499,Africa,51.407,3246.991771 +Algeria,1972,14760787,Africa,54.518,4182.663766 +Algeria,1977,17152804,Africa,58.014,4910.416756 +Algeria,1982,20033753,Africa,61.368,5745.160213 +Algeria,1987,23254956,Africa,65.799,5681.358539 +Algeria,1992,26298373,Africa,67.744,5023.216647 +Algeria,1997,29072015,Africa,69.152,4797.295051 +Algeria,2002,31287142,Africa,70.994,5288.040382 +Algeria,2007,33333216,Africa,72.301,6223.367465 +Angola,1952,4232095,Africa,30.015,3520.610273 +Angola,1957,4561361,Africa,31.999,3827.940465 +Angola,1962,4826015,Africa,34,4269.276742 +Angola,1967,5247469,Africa,35.985,5522.776375 +Angola,1972,5894858,Africa,37.928,5473.288005 +Angola,1977,6162675,Africa,39.483,3008.647355 +Angola,1982,7016384,Africa,39.942,2756.953672 +Angola,1987,7874230,Africa,39.906,2430.208311 +Angola,1992,8735988,Africa,40.647,2627.845685 +Angola,1997,9875024,Africa,40.963,2277.140884 +Angola,2002,10866106,Africa,41.003,2773.287312 +Angola,2007,12420476,Africa,42.731,4797.231267 +Argentina,1952,17876956,Americas,62.485,5911.315053 +Argentina,1957,19610538,Americas,64.399,6856.856212 +Argentina,1962,21283783,Americas,65.142,7133.166023 +Argentina,1967,22934225,Americas,65.634,8052.953021 +Argentina,1972,24779799,Americas,67.065,9443.038526 +Argentina,1977,26983828,Americas,68.481,10079.02674 +Argentina,1982,29341374,Americas,69.942,8997.897412 +Argentina,1987,31620918,Americas,70.774,9139.671389 +Argentina,1992,33958947,Americas,71.868,9308.41871 +Argentina,1997,36203463,Americas,73.275,10967.28195 +Argentina,2002,38331121,Americas,74.34,8797.640716 +Argentina,2007,40301927,Americas,75.32,12779.37964 +Australia,1952,8691212,Oceania,69.12,10039.59564 +Australia,1957,9712569,Oceania,70.33,10949.64959 +Australia,1962,10794968,Oceania,70.93,12217.22686 +Australia,1967,11872264,Oceania,71.1,14526.12465 +Australia,1972,13177000,Oceania,71.93,16788.62948 +Australia,1977,14074100,Oceania,73.49,18334.19751 +Australia,1982,15184200,Oceania,74.74,19477.00928 +Australia,1987,16257249,Oceania,76.32,21888.88903 +Australia,1992,17481977,Oceania,77.56,23424.76683 +Australia,1997,18565243,Oceania,78.83,26997.93657 +Australia,2002,19546792,Oceania,80.37,30687.75473 +Australia,2007,20434176,Oceania,81.235,34435.36744 +Austria,1952,6927772,Europe,66.8,6137.076492 +Austria,1957,6965860,Europe,67.48,8842.59803 +Austria,1962,7129864,Europe,69.54,10750.72111 +Austria,1967,7376998,Europe,70.14,12834.6024 +Austria,1972,7544201,Europe,70.63,16661.6256 +Austria,1977,7568430,Europe,72.17,19749.4223 +Austria,1982,7574613,Europe,73.18,21597.08362 +Austria,1987,7578903,Europe,74.94,23687.82607 +Austria,1992,7914969,Europe,76.04,27042.01868 +Austria,1997,8069876,Europe,77.51,29095.92066 +Austria,2002,8148312,Europe,78.98,32417.60769 +Austria,2007,8199783,Europe,79.829,36126.4927 +Bahrain,1952,120447,Asia,50.939,9867.084765 +Bahrain,1957,138655,Asia,53.832,11635.79945 +Bahrain,1962,171863,Asia,56.923,12753.27514 +Bahrain,1967,202182,Asia,59.923,14804.6727 +Bahrain,1972,230800,Asia,63.3,18268.65839 +Bahrain,1977,297410,Asia,65.593,19340.10196 +Bahrain,1982,377967,Asia,69.052,19211.14731 +Bahrain,1987,454612,Asia,70.75,18524.02406 +Bahrain,1992,529491,Asia,72.601,19035.57917 +Bahrain,1997,598561,Asia,73.925,20292.01679 +Bahrain,2002,656397,Asia,74.795,23403.55927 +Bahrain,2007,708573,Asia,75.635,29796.04834 +Bangladesh,1952,46886859,Asia,37.484,684.2441716 +Bangladesh,1957,51365468,Asia,39.348,661.6374577 +Bangladesh,1962,56839289,Asia,41.216,686.3415538 +Bangladesh,1967,62821884,Asia,43.453,721.1860862 +Bangladesh,1972,70759295,Asia,45.252,630.2336265 +Bangladesh,1977,80428306,Asia,46.923,659.8772322 +Bangladesh,1982,93074406,Asia,50.009,676.9818656 +Bangladesh,1987,103764241,Asia,52.819,751.9794035 +Bangladesh,1992,113704579,Asia,56.018,837.8101643 +Bangladesh,1997,123315288,Asia,59.412,972.7700352 +Bangladesh,2002,135656790,Asia,62.013,1136.39043 +Bangladesh,2007,150448339,Asia,64.062,1391.253792 +Belgium,1952,8730405,Europe,68,8343.105127 +Belgium,1957,8989111,Europe,69.24,9714.960623 +Belgium,1962,9218400,Europe,70.25,10991.20676 +Belgium,1967,9556500,Europe,70.94,13149.04119 +Belgium,1972,9709100,Europe,71.44,16672.14356 +Belgium,1977,9821800,Europe,72.8,19117.97448 +Belgium,1982,9856303,Europe,73.93,20979.84589 +Belgium,1987,9870200,Europe,75.35,22525.56308 +Belgium,1992,10045622,Europe,76.46,25575.57069 +Belgium,1997,10199787,Europe,77.53,27561.19663 +Belgium,2002,10311970,Europe,78.32,30485.88375 +Belgium,2007,10392226,Europe,79.441,33692.60508 +Benin,1952,1738315,Africa,38.223,1062.7522 +Benin,1957,1925173,Africa,40.358,959.6010805 +Benin,1962,2151895,Africa,42.618,949.4990641 +Benin,1967,2427334,Africa,44.885,1035.831411 +Benin,1972,2761407,Africa,47.014,1085.796879 +Benin,1977,3168267,Africa,49.19,1029.161251 +Benin,1982,3641603,Africa,50.904,1277.897616 +Benin,1987,4243788,Africa,52.337,1225.85601 +Benin,1992,4981671,Africa,53.919,1191.207681 +Benin,1997,6066080,Africa,54.777,1232.975292 +Benin,2002,7026113,Africa,54.406,1372.877931 +Benin,2007,8078314,Africa,56.728,1441.284873 +Bolivia,1952,2883315,Americas,40.414,2677.326347 +Bolivia,1957,3211738,Americas,41.89,2127.686326 +Bolivia,1962,3593918,Americas,43.428,2180.972546 +Bolivia,1967,4040665,Americas,45.032,2586.886053 +Bolivia,1972,4565872,Americas,46.714,2980.331339 +Bolivia,1977,5079716,Americas,50.023,3548.097832 +Bolivia,1982,5642224,Americas,53.859,3156.510452 +Bolivia,1987,6156369,Americas,57.251,2753.69149 +Bolivia,1992,6893451,Americas,59.957,2961.699694 +Bolivia,1997,7693188,Americas,62.05,3326.143191 +Bolivia,2002,8445134,Americas,63.883,3413.26269 +Bolivia,2007,9119152,Americas,65.554,3822.137084 +Bosnia and Herzegovina,1952,2791000,Europe,53.82,973.5331948 +Bosnia and Herzegovina,1957,3076000,Europe,58.45,1353.989176 +Bosnia and Herzegovina,1962,3349000,Europe,61.93,1709.683679 +Bosnia and Herzegovina,1967,3585000,Europe,64.79,2172.352423 +Bosnia and Herzegovina,1972,3819000,Europe,67.45,2860.16975 +Bosnia and Herzegovina,1977,4086000,Europe,69.86,3528.481305 +Bosnia and Herzegovina,1982,4172693,Europe,70.69,4126.613157 +Bosnia and Herzegovina,1987,4338977,Europe,71.14,4314.114757 +Bosnia and Herzegovina,1992,4256013,Europe,72.178,2546.781445 +Bosnia and Herzegovina,1997,3607000,Europe,73.244,4766.355904 +Bosnia and Herzegovina,2002,4165416,Europe,74.09,6018.975239 +Bosnia and Herzegovina,2007,4552198,Europe,74.852,7446.298803 +Botswana,1952,442308,Africa,47.622,851.2411407 +Botswana,1957,474639,Africa,49.618,918.2325349 +Botswana,1962,512764,Africa,51.52,983.6539764 +Botswana,1967,553541,Africa,53.298,1214.709294 +Botswana,1972,619351,Africa,56.024,2263.611114 +Botswana,1977,781472,Africa,59.319,3214.857818 +Botswana,1982,970347,Africa,61.484,4551.14215 +Botswana,1987,1151184,Africa,63.622,6205.88385 +Botswana,1992,1342614,Africa,62.745,7954.111645 +Botswana,1997,1536536,Africa,52.556,8647.142313 +Botswana,2002,1630347,Africa,46.634,11003.60508 +Botswana,2007,1639131,Africa,50.728,12569.85177 +Brazil,1952,56602560,Americas,50.917,2108.944355 +Brazil,1957,65551171,Americas,53.285,2487.365989 +Brazil,1962,76039390,Americas,55.665,3336.585802 +Brazil,1967,88049823,Americas,57.632,3429.864357 +Brazil,1972,100840058,Americas,59.504,4985.711467 +Brazil,1977,114313951,Americas,61.489,6660.118654 +Brazil,1982,128962939,Americas,63.336,7030.835878 +Brazil,1987,142938076,Americas,65.205,7807.095818 +Brazil,1992,155975974,Americas,67.057,6950.283021 +Brazil,1997,168546719,Americas,69.388,7957.980824 +Brazil,2002,179914212,Americas,71.006,8131.212843 +Brazil,2007,190010647,Americas,72.39,9065.800825 +Bulgaria,1952,7274900,Europe,59.6,2444.286648 +Bulgaria,1957,7651254,Europe,66.61,3008.670727 +Bulgaria,1962,8012946,Europe,69.51,4254.337839 +Bulgaria,1967,8310226,Europe,70.42,5577.0028 +Bulgaria,1972,8576200,Europe,70.9,6597.494398 +Bulgaria,1977,8797022,Europe,70.81,7612.240438 +Bulgaria,1982,8892098,Europe,71.08,8224.191647 +Bulgaria,1987,8971958,Europe,71.34,8239.854824 +Bulgaria,1992,8658506,Europe,71.19,6302.623438 +Bulgaria,1997,8066057,Europe,70.32,5970.38876 +Bulgaria,2002,7661799,Europe,72.14,7696.777725 +Bulgaria,2007,7322858,Europe,73.005,10680.79282 +Burkina Faso,1952,4469979,Africa,31.975,543.2552413 +Burkina Faso,1957,4713416,Africa,34.906,617.1834648 +Burkina Faso,1962,4919632,Africa,37.814,722.5120206 +Burkina Faso,1967,5127935,Africa,40.697,794.8265597 +Burkina Faso,1972,5433886,Africa,43.591,854.7359763 +Burkina Faso,1977,5889574,Africa,46.137,743.3870368 +Burkina Faso,1982,6634596,Africa,48.122,807.1985855 +Burkina Faso,1987,7586551,Africa,49.557,912.0631417 +Burkina Faso,1992,8878303,Africa,50.26,931.7527731 +Burkina Faso,1997,10352843,Africa,50.324,946.2949618 +Burkina Faso,2002,12251209,Africa,50.65,1037.645221 +Burkina Faso,2007,14326203,Africa,52.295,1217.032994 +Burundi,1952,2445618,Africa,39.031,339.2964587 +Burundi,1957,2667518,Africa,40.533,379.5646281 +Burundi,1962,2961915,Africa,42.045,355.2032273 +Burundi,1967,3330989,Africa,43.548,412.9775136 +Burundi,1972,3529983,Africa,44.057,464.0995039 +Burundi,1977,3834415,Africa,45.91,556.1032651 +Burundi,1982,4580410,Africa,47.471,559.603231 +Burundi,1987,5126023,Africa,48.211,621.8188189 +Burundi,1992,5809236,Africa,44.736,631.6998778 +Burundi,1997,6121610,Africa,45.326,463.1151478 +Burundi,2002,7021078,Africa,47.36,446.4035126 +Burundi,2007,8390505,Africa,49.58,430.0706916 +Cambodia,1952,4693836,Asia,39.417,368.4692856 +Cambodia,1957,5322536,Asia,41.366,434.0383364 +Cambodia,1962,6083619,Asia,43.415,496.9136476 +Cambodia,1967,6960067,Asia,45.415,523.4323142 +Cambodia,1972,7450606,Asia,40.317,421.6240257 +Cambodia,1977,6978607,Asia,31.22,524.9721832 +Cambodia,1982,7272485,Asia,50.957,624.4754784 +Cambodia,1987,8371791,Asia,53.914,683.8955732 +Cambodia,1992,10150094,Asia,55.803,682.3031755 +Cambodia,1997,11782962,Asia,56.534,734.28517 +Cambodia,2002,12926707,Asia,56.752,896.2260153 +Cambodia,2007,14131858,Asia,59.723,1713.778686 +Cameroon,1952,5009067,Africa,38.523,1172.667655 +Cameroon,1957,5359923,Africa,40.428,1313.048099 +Cameroon,1962,5793633,Africa,42.643,1399.607441 +Cameroon,1967,6335506,Africa,44.799,1508.453148 +Cameroon,1972,7021028,Africa,47.049,1684.146528 +Cameroon,1977,7959865,Africa,49.355,1783.432873 +Cameroon,1982,9250831,Africa,52.961,2367.983282 +Cameroon,1987,10780667,Africa,54.985,2602.664206 +Cameroon,1992,12467171,Africa,54.314,1793.163278 +Cameroon,1997,14195809,Africa,52.199,1694.337469 +Cameroon,2002,15929988,Africa,49.856,1934.011449 +Cameroon,2007,17696293,Africa,50.43,2042.09524 +Canada,1952,14785584,Americas,68.75,11367.16112 +Canada,1957,17010154,Americas,69.96,12489.95006 +Canada,1962,18985849,Americas,71.3,13462.48555 +Canada,1967,20819767,Americas,72.13,16076.58803 +Canada,1972,22284500,Americas,72.88,18970.57086 +Canada,1977,23796400,Americas,74.21,22090.88306 +Canada,1982,25201900,Americas,75.76,22898.79214 +Canada,1987,26549700,Americas,76.86,26626.51503 +Canada,1992,28523502,Americas,77.95,26342.88426 +Canada,1997,30305843,Americas,78.61,28954.92589 +Canada,2002,31902268,Americas,79.77,33328.96507 +Canada,2007,33390141,Americas,80.653,36319.23501 +Central African Republic,1952,1291695,Africa,35.463,1071.310713 +Central African Republic,1957,1392284,Africa,37.464,1190.844328 +Central African Republic,1962,1523478,Africa,39.475,1193.068753 +Central African Republic,1967,1733638,Africa,41.478,1136.056615 +Central African Republic,1972,1927260,Africa,43.457,1070.013275 +Central African Republic,1977,2167533,Africa,46.775,1109.374338 +Central African Republic,1982,2476971,Africa,48.295,956.7529907 +Central African Republic,1987,2840009,Africa,50.485,844.8763504 +Central African Republic,1992,3265124,Africa,49.396,747.9055252 +Central African Republic,1997,3696513,Africa,46.066,740.5063317 +Central African Republic,2002,4048013,Africa,43.308,738.6906068 +Central African Republic,2007,4369038,Africa,44.741,706.016537 +Chad,1952,2682462,Africa,38.092,1178.665927 +Chad,1957,2894855,Africa,39.881,1308.495577 +Chad,1962,3150417,Africa,41.716,1389.817618 +Chad,1967,3495967,Africa,43.601,1196.810565 +Chad,1972,3899068,Africa,45.569,1104.103987 +Chad,1977,4388260,Africa,47.383,1133.98495 +Chad,1982,4875118,Africa,49.517,797.9081006 +Chad,1987,5498955,Africa,51.051,952.386129 +Chad,1992,6429417,Africa,51.724,1058.0643 +Chad,1997,7562011,Africa,51.573,1004.961353 +Chad,2002,8835739,Africa,50.525,1156.18186 +Chad,2007,10238807,Africa,50.651,1704.063724 +Chile,1952,6377619,Americas,54.745,3939.978789 +Chile,1957,7048426,Americas,56.074,4315.622723 +Chile,1962,7961258,Americas,57.924,4519.094331 +Chile,1967,8858908,Americas,60.523,5106.654313 +Chile,1972,9717524,Americas,63.441,5494.024437 +Chile,1977,10599793,Americas,67.052,4756.763836 +Chile,1982,11487112,Americas,70.565,5095.665738 +Chile,1987,12463354,Americas,72.492,5547.063754 +Chile,1992,13572994,Americas,74.126,7596.125964 +Chile,1997,14599929,Americas,75.816,10118.05318 +Chile,2002,15497046,Americas,77.86,10778.78385 +Chile,2007,16284741,Americas,78.553,13171.63885 +China,1952,556263527.999989,Asia,44,400.448610699994 +China,1957,637408000,Asia,50.54896,575.9870009 +China,1962,665770000,Asia,44.50136,487.6740183 +China,1967,754550000,Asia,58.38112,612.7056934 +China,1972,862030000,Asia,63.11888,676.9000921 +China,1977,943455000,Asia,63.96736,741.2374699 +China,1982,1000281000,Asia,65.525,962.4213805 +China,1987,1084035000,Asia,67.274,1378.904018 +China,1992,1164970000,Asia,68.69,1655.784158 +China,1997,1230075000,Asia,70.426,2289.234136 +China,2002,1280400000,Asia,72.028,3119.280896 +China,2007,1318683096,Asia,72.961,4959.114854 +Colombia,1952,12350771,Americas,50.643,2144.115096 +Colombia,1957,14485993,Americas,55.118,2323.805581 +Colombia,1962,17009885,Americas,57.863,2492.351109 +Colombia,1967,19764027,Americas,59.963,2678.729839 +Colombia,1972,22542890,Americas,61.623,3264.660041 +Colombia,1977,25094412,Americas,63.837,3815.80787 +Colombia,1982,27764644,Americas,66.653,4397.575659 +Colombia,1987,30964245,Americas,67.768,4903.2191 +Colombia,1992,34202721,Americas,68.421,5444.648617 +Colombia,1997,37657830,Americas,70.313,6117.361746 +Colombia,2002,41008227,Americas,71.682,5755.259962 +Colombia,2007,44227550,Americas,72.889,7006.580419 +Comoros,1952,153936,Africa,40.715,1102.990936 +Comoros,1957,170928,Africa,42.46,1211.148548 +Comoros,1962,191689,Africa,44.467,1406.648278 +Comoros,1967,217378,Africa,46.472,1876.029643 +Comoros,1972,250027,Africa,48.944,1937.577675 +Comoros,1977,304739,Africa,50.939,1172.603047 +Comoros,1982,348643,Africa,52.933,1267.100083 +Comoros,1987,395114,Africa,54.926,1315.980812 +Comoros,1992,454429,Africa,57.939,1246.90737 +Comoros,1997,527982,Africa,60.66,1173.618235 +Comoros,2002,614382,Africa,62.974,1075.811558 +Comoros,2007,710960,Africa,65.152,986.1478792 +Congo Dem. Rep.,1952,14100005,Africa,39.143,780.5423257 +Congo Dem. Rep.,1957,15577932,Africa,40.652,905.8602303 +Congo Dem. Rep.,1962,17486434,Africa,42.122,896.3146335 +Congo Dem. Rep.,1967,19941073,Africa,44.056,861.5932424 +Congo Dem. Rep.,1972,23007669,Africa,45.989,904.8960685 +Congo Dem. Rep.,1977,26480870,Africa,47.804,795.757282 +Congo Dem. Rep.,1982,30646495,Africa,47.784,673.7478181 +Congo Dem. Rep.,1987,35481645,Africa,47.412,672.774812 +Congo Dem. Rep.,1992,41672143,Africa,45.548,457.7191807 +Congo Dem. Rep.,1997,47798986,Africa,42.587,312.188423 +Congo Dem. Rep.,2002,55379852,Africa,44.966,241.1658765 +Congo Dem. Rep.,2007,64606759,Africa,46.462,277.5518587 +Congo Rep.,1952,854885,Africa,42.111,2125.621418 +Congo Rep.,1957,940458,Africa,45.053,2315.056572 +Congo Rep.,1962,1047924,Africa,48.435,2464.783157 +Congo Rep.,1967,1179760,Africa,52.04,2677.939642 +Congo Rep.,1972,1340458,Africa,54.907,3213.152683 +Congo Rep.,1977,1536769,Africa,55.625,3259.178978 +Congo Rep.,1982,1774735,Africa,56.695,4879.507522 +Congo Rep.,1987,2064095,Africa,57.47,4201.194937 +Congo Rep.,1992,2409073,Africa,56.433,4016.239529 +Congo Rep.,1997,2800947,Africa,52.962,3484.164376 +Congo Rep.,2002,3328795,Africa,52.97,3484.06197 +Congo Rep.,2007,3800610,Africa,55.322,3632.557798 +Costa Rica,1952,926317,Americas,57.206,2627.009471 +Costa Rica,1957,1112300,Americas,60.026,2990.010802 +Costa Rica,1962,1345187,Americas,62.842,3460.937025 +Costa Rica,1967,1588717,Americas,65.424,4161.727834 +Costa Rica,1972,1834796,Americas,67.849,5118.146939 +Costa Rica,1977,2108457,Americas,70.75,5926.876967 +Costa Rica,1982,2424367,Americas,73.45,5262.734751 +Costa Rica,1987,2799811,Americas,74.752,5629.915318 +Costa Rica,1992,3173216,Americas,75.713,6160.416317 +Costa Rica,1997,3518107,Americas,77.26,6677.045314 +Costa Rica,2002,3834934,Americas,78.123,7723.447195 +Costa Rica,2007,4133884,Americas,78.782,9645.06142 +"Cote d'Ivoire",1952,2977019,Africa,40.477,1388.594732 +"Cote d'Ivoire",1957,3300000,Africa,42.469,1500.895925 +"Cote d'Ivoire",1962,3832408,Africa,44.93,1728.869428 +"Cote d'Ivoire",1967,4744870,Africa,47.35,2052.050473 +"Cote d'Ivoire",1972,6071696,Africa,49.801,2378.201111 +"Cote d'Ivoire",1977,7459574,Africa,52.374,2517.736547 +"Cote d'Ivoire",1982,9025951,Africa,53.983,2602.710169 +"Cote d'Ivoire",1987,10761098,Africa,54.655,2156.956069 +"Cote d'Ivoire",1992,12772596,Africa,52.044,1648.073791 +"Cote d'Ivoire",1997,14625967,Africa,47.991,1786.265407 +"Cote d'Ivoire",2002,16252726,Africa,46.832,1648.800823 +"Cote d'Ivoire",2007,18013409,Africa,48.328,1544.750112 +Croatia,1952,3882229,Europe,61.21,3119.23652 +Croatia,1957,3991242,Europe,64.77,4338.231617 +Croatia,1962,4076557,Europe,67.13,5477.890018 +Croatia,1967,4174366,Europe,68.5,6960.297861 +Croatia,1972,4225310,Europe,69.61,9164.090127 +Croatia,1977,4318673,Europe,70.64,11305.38517 +Croatia,1982,4413368,Europe,70.46,13221.82184 +Croatia,1987,4484310,Europe,71.52,13822.58394 +Croatia,1992,4494013,Europe,72.527,8447.794873 +Croatia,1997,4444595,Europe,73.68,9875.604515 +Croatia,2002,4481020,Europe,74.876,11628.38895 +Croatia,2007,4493312,Europe,75.748,14619.22272 +Cuba,1952,6007797,Americas,59.421,5586.53878 +Cuba,1957,6640752,Americas,62.325,6092.174359 +Cuba,1962,7254373,Americas,65.246,5180.75591 +Cuba,1967,8139332,Americas,68.29,5690.268015 +Cuba,1972,8831348,Americas,70.723,5305.445256 +Cuba,1977,9537988,Americas,72.649,6380.494966 +Cuba,1982,9789224,Americas,73.717,7316.918107 +Cuba,1987,10239839,Americas,74.174,7532.924763 +Cuba,1992,10723260,Americas,74.414,5592.843963 +Cuba,1997,10983007,Americas,76.151,5431.990415 +Cuba,2002,11226999,Americas,77.158,6340.646683 +Cuba,2007,11416987,Americas,78.273,8948.102923 +Czech Republic,1952,9125183,Europe,66.87,6876.14025 +Czech Republic,1957,9513758,Europe,69.03,8256.343918 +Czech Republic,1962,9620282,Europe,69.9,10136.86713 +Czech Republic,1967,9835109,Europe,70.38,11399.44489 +Czech Republic,1972,9862158,Europe,70.29,13108.4536 +Czech Republic,1977,10161915,Europe,70.71,14800.16062 +Czech Republic,1982,10303704,Europe,70.96,15377.22855 +Czech Republic,1987,10311597,Europe,71.58,16310.4434 +Czech Republic,1992,10315702,Europe,72.4,14297.02122 +Czech Republic,1997,10300707,Europe,74.01,16048.51424 +Czech Republic,2002,10256295,Europe,75.51,17596.21022 +Czech Republic,2007,10228744,Europe,76.486,22833.30851 +Denmark,1952,4334000,Europe,70.78,9692.385245 +Denmark,1957,4487831,Europe,71.81,11099.65935 +Denmark,1962,4646899,Europe,72.35,13583.31351 +Denmark,1967,4838800,Europe,72.96,15937.21123 +Denmark,1972,4991596,Europe,73.47,18866.20721 +Denmark,1977,5088419,Europe,74.69,20422.9015 +Denmark,1982,5117810,Europe,74.63,21688.04048 +Denmark,1987,5127024,Europe,74.8,25116.17581 +Denmark,1992,5171393,Europe,75.33,26406.73985 +Denmark,1997,5283663,Europe,76.11,29804.34567 +Denmark,2002,5374693,Europe,77.18,32166.50006 +Denmark,2007,5468120,Europe,78.332,35278.41874 +Djibouti,1952,63149,Africa,34.812,2669.529475 +Djibouti,1957,71851,Africa,37.328,2864.969076 +Djibouti,1962,89898,Africa,39.693,3020.989263 +Djibouti,1967,127617,Africa,42.074,3020.050513 +Djibouti,1972,178848,Africa,44.366,3694.212352 +Djibouti,1977,228694,Africa,46.519,3081.761022 +Djibouti,1982,305991,Africa,48.812,2879.468067 +Djibouti,1987,311025,Africa,50.04,2880.102568 +Djibouti,1992,384156,Africa,51.604,2377.156192 +Djibouti,1997,417908,Africa,53.157,1895.016984 +Djibouti,2002,447416,Africa,53.373,1908.260867 +Djibouti,2007,496374,Africa,54.791,2082.481567 +Dominican Republic,1952,2491346,Americas,45.928,1397.717137 +Dominican Republic,1957,2923186,Americas,49.828,1544.402995 +Dominican Republic,1962,3453434,Americas,53.459,1662.137359 +Dominican Republic,1967,4049146,Americas,56.751,1653.723003 +Dominican Republic,1972,4671329,Americas,59.631,2189.874499 +Dominican Republic,1977,5302800,Americas,61.788,2681.9889 +Dominican Republic,1982,5968349,Americas,63.727,2861.092386 +Dominican Republic,1987,6655297,Americas,66.046,2899.842175 +Dominican Republic,1992,7351181,Americas,68.457,3044.214214 +Dominican Republic,1997,7992357,Americas,69.957,3614.101285 +Dominican Republic,2002,8650322,Americas,70.847,4563.808154 +Dominican Republic,2007,9319622,Americas,72.235,6025.374752 +Ecuador,1952,3548753,Americas,48.357,3522.110717 +Ecuador,1957,4058385,Americas,51.356,3780.546651 +Ecuador,1962,4681707,Americas,54.64,4086.114078 +Ecuador,1967,5432424,Americas,56.678,4579.074215 +Ecuador,1972,6298651,Americas,58.796,5280.99471 +Ecuador,1977,7278866,Americas,61.31,6679.62326 +Ecuador,1982,8365850,Americas,64.342,7213.791267 +Ecuador,1987,9545158,Americas,67.231,6481.776993 +Ecuador,1992,10748394,Americas,69.613,7103.702595 +Ecuador,1997,11911819,Americas,72.312,7429.455877 +Ecuador,2002,12921234,Americas,74.173,5773.044512 +Ecuador,2007,13755680,Americas,74.994,6873.262326 +Egypt,1952,22223309,Africa,41.893,1418.822445 +Egypt,1957,25009741,Africa,44.444,1458.915272 +Egypt,1962,28173309,Africa,46.992,1693.335853 +Egypt,1967,31681188,Africa,49.293,1814.880728 +Egypt,1972,34807417,Africa,51.137,2024.008147 +Egypt,1977,38783863,Africa,53.319,2785.493582 +Egypt,1982,45681811,Africa,56.006,3503.729636 +Egypt,1987,52799062,Africa,59.797,3885.46071 +Egypt,1992,59402198,Africa,63.674,3794.755195 +Egypt,1997,66134291,Africa,67.217,4173.181797 +Egypt,2002,73312559,Africa,69.806,4754.604414 +Egypt,2007,80264543,Africa,71.338,5581.180998 +El Salvador,1952,2042865,Americas,45.262,3048.3029 +El Salvador,1957,2355805,Americas,48.57,3421.523218 +El Salvador,1962,2747687,Americas,52.307,3776.803627 +El Salvador,1967,3232927,Americas,55.855,4358.595393 +El Salvador,1972,3790903,Americas,58.207,4520.246008 +El Salvador,1977,4282586,Americas,56.696,5138.922374 +El Salvador,1982,4474873,Americas,56.604,4098.344175 +El Salvador,1987,4842194,Americas,63.154,4140.442097 +El Salvador,1992,5274649,Americas,66.798,4444.2317 +El Salvador,1997,5783439,Americas,69.535,5154.825496 +El Salvador,2002,6353681,Americas,70.734,5351.568666 +El Salvador,2007,6939688,Americas,71.878,5728.353514 +Equatorial Guinea,1952,216964,Africa,34.482,375.6431231 +Equatorial Guinea,1957,232922,Africa,35.983,426.0964081 +Equatorial Guinea,1962,249220,Africa,37.485,582.8419714 +Equatorial Guinea,1967,259864,Africa,38.987,915.5960025 +Equatorial Guinea,1972,277603,Africa,40.516,672.4122571 +Equatorial Guinea,1977,192675,Africa,42.024,958.5668124 +Equatorial Guinea,1982,285483,Africa,43.662,927.8253427 +Equatorial Guinea,1987,341244,Africa,45.664,966.8968149 +Equatorial Guinea,1992,387838,Africa,47.545,1132.055034 +Equatorial Guinea,1997,439971,Africa,48.245,2814.480755 +Equatorial Guinea,2002,495627,Africa,49.348,7703.4959 +Equatorial Guinea,2007,551201,Africa,51.579,12154.08975 +Eritrea,1952,1438760,Africa,35.928,328.9405571 +Eritrea,1957,1542611,Africa,38.047,344.1618859 +Eritrea,1962,1666618,Africa,40.158,380.9958433 +Eritrea,1967,1820319,Africa,42.189,468.7949699 +Eritrea,1972,2260187,Africa,44.142,514.3242082 +Eritrea,1977,2512642,Africa,44.535,505.7538077 +Eritrea,1982,2637297,Africa,43.89,524.8758493 +Eritrea,1987,2915959,Africa,46.453,521.1341333 +Eritrea,1992,3668440,Africa,49.991,582.8585102 +Eritrea,1997,4058319,Africa,53.378,913.47079 +Eritrea,2002,4414865,Africa,55.24,765.3500015 +Eritrea,2007,4906585,Africa,58.04,641.3695236 +Ethiopia,1952,20860941,Africa,34.078,362.1462796 +Ethiopia,1957,22815614,Africa,36.667,378.9041632 +Ethiopia,1962,25145372,Africa,40.059,419.4564161 +Ethiopia,1967,27860297,Africa,42.115,516.1186438 +Ethiopia,1972,30770372,Africa,43.515,566.2439442 +Ethiopia,1977,34617799,Africa,44.51,556.8083834 +Ethiopia,1982,38111756,Africa,44.916,577.8607471 +Ethiopia,1987,42999530,Africa,46.684,573.7413142 +Ethiopia,1992,52088559,Africa,48.091,421.3534653 +Ethiopia,1997,59861301,Africa,49.402,515.8894013 +Ethiopia,2002,67946797,Africa,50.725,530.0535319 +Ethiopia,2007,76511887,Africa,52.947,690.8055759 +Finland,1952,4090500,Europe,66.55,6424.519071 +Finland,1957,4324000,Europe,67.49,7545.415386 +Finland,1962,4491443,Europe,68.75,9371.842561 +Finland,1967,4605744,Europe,69.83,10921.63626 +Finland,1972,4639657,Europe,70.87,14358.8759 +Finland,1977,4738902,Europe,72.52,15605.42283 +Finland,1982,4826933,Europe,74.55,18533.15761 +Finland,1987,4931729,Europe,74.83,21141.01223 +Finland,1992,5041039,Europe,75.7,20647.16499 +Finland,1997,5134406,Europe,77.13,23723.9502 +Finland,2002,5193039,Europe,78.37,28204.59057 +Finland,2007,5238460,Europe,79.313,33207.0844 +France,1952,42459667,Europe,67.41,7029.809327 +France,1957,44310863,Europe,68.93,8662.834898 +France,1962,47124000,Europe,70.51,10560.48553 +France,1967,49569000,Europe,71.55,12999.91766 +France,1972,51732000,Europe,72.38,16107.19171 +France,1977,53165019,Europe,73.83,18292.63514 +France,1982,54433565,Europe,74.89,20293.89746 +France,1987,55630100,Europe,76.34,22066.44214 +France,1992,57374179,Europe,77.46,24703.79615 +France,1997,58623428,Europe,78.64,25889.78487 +France,2002,59925035,Europe,79.59,28926.03234 +France,2007,61083916,Europe,80.657,30470.0167 +Gabon,1952,420702,Africa,37.003,4293.476475 +Gabon,1957,434904,Africa,38.999,4976.198099 +Gabon,1962,455661,Africa,40.489,6631.459222 +Gabon,1967,489004,Africa,44.598,8358.761987 +Gabon,1972,537977,Africa,48.69,11401.94841 +Gabon,1977,706367,Africa,52.79,21745.57328 +Gabon,1982,753874,Africa,56.564,15113.36194 +Gabon,1987,880397,Africa,60.19,11864.40844 +Gabon,1992,985739,Africa,61.366,13522.15752 +Gabon,1997,1126189,Africa,60.461,14722.84188 +Gabon,2002,1299304,Africa,56.761,12521.71392 +Gabon,2007,1454867,Africa,56.735,13206.48452 +Gambia,1952,284320,Africa,30,485.2306591 +Gambia,1957,323150,Africa,32.065,520.9267111 +Gambia,1962,374020,Africa,33.896,599.650276 +Gambia,1967,439593,Africa,35.857,734.7829124 +Gambia,1972,517101,Africa,38.308,756.0868363 +Gambia,1977,608274,Africa,41.842,884.7552507 +Gambia,1982,715523,Africa,45.58,835.8096108 +Gambia,1987,848406,Africa,49.265,611.6588611 +Gambia,1992,1025384,Africa,52.644,665.6244126 +Gambia,1997,1235767,Africa,55.861,653.7301704 +Gambia,2002,1457766,Africa,58.041,660.5855997 +Gambia,2007,1688359,Africa,59.448,752.7497265 +Germany,1952,69145952,Europe,67.5,7144.114393 +Germany,1957,71019069,Europe,69.1,10187.82665 +Germany,1962,73739117,Europe,70.3,12902.46291 +Germany,1967,76368453,Europe,70.8,14745.62561 +Germany,1972,78717088,Europe,71,18016.18027 +Germany,1977,78160773,Europe,72.5,20512.92123 +Germany,1982,78335266,Europe,73.8,22031.53274 +Germany,1987,77718298,Europe,74.847,24639.18566 +Germany,1992,80597764,Europe,76.07,26505.30317 +Germany,1997,82011073,Europe,77.34,27788.88416 +Germany,2002,82350671,Europe,78.67,30035.80198 +Germany,2007,82400996,Europe,79.406,32170.37442 +Ghana,1952,5581001,Africa,43.149,911.2989371 +Ghana,1957,6391288,Africa,44.779,1043.561537 +Ghana,1962,7355248,Africa,46.452,1190.041118 +Ghana,1967,8490213,Africa,48.072,1125.69716 +Ghana,1972,9354120,Africa,49.875,1178.223708 +Ghana,1977,10538093,Africa,51.756,993.2239571 +Ghana,1982,11400338,Africa,53.744,876.032569 +Ghana,1987,14168101,Africa,55.729,847.0061135 +Ghana,1992,16278738,Africa,57.501,925.060154 +Ghana,1997,18418288,Africa,58.556,1005.245812 +Ghana,2002,20550751,Africa,58.453,1111.984578 +Ghana,2007,22873338,Africa,60.022,1327.60891 +Greece,1952,7733250,Europe,65.86,3530.690067 +Greece,1957,8096218,Europe,67.86,4916.299889 +Greece,1962,8448233,Europe,69.51,6017.190733 +Greece,1967,8716441,Europe,71,8513.097016 +Greece,1972,8888628,Europe,72.34,12724.82957 +Greece,1977,9308479,Europe,73.68,14195.52428 +Greece,1982,9786480,Europe,75.24,15268.42089 +Greece,1987,9974490,Europe,76.67,16120.52839 +Greece,1992,10325429,Europe,77.03,17541.49634 +Greece,1997,10502372,Europe,77.869,18747.69814 +Greece,2002,10603863,Europe,78.256,22514.2548 +Greece,2007,10706290,Europe,79.483,27538.41188 +Guatemala,1952,3146381,Americas,42.023,2428.237769 +Guatemala,1957,3640876,Americas,44.142,2617.155967 +Guatemala,1962,4208858,Americas,46.954,2750.364446 +Guatemala,1967,4690773,Americas,50.016,3242.531147 +Guatemala,1972,5149581,Americas,53.738,4031.408271 +Guatemala,1977,5703430,Americas,56.029,4879.992748 +Guatemala,1982,6395630,Americas,58.137,4820.49479 +Guatemala,1987,7326406,Americas,60.782,4246.485974 +Guatemala,1992,8486949,Americas,63.373,4439.45084 +Guatemala,1997,9803875,Americas,66.322,4684.313807 +Guatemala,2002,11178650,Americas,68.978,4858.347495 +Guatemala,2007,12572928,Americas,70.259,5186.050003 +Guinea,1952,2664249,Africa,33.609,510.1964923 +Guinea,1957,2876726,Africa,34.558,576.2670245 +Guinea,1962,3140003,Africa,35.753,686.3736739 +Guinea,1967,3451418,Africa,37.197,708.7595409 +Guinea,1972,3811387,Africa,38.842,741.6662307 +Guinea,1977,4227026,Africa,40.762,874.6858643 +Guinea,1982,4710497,Africa,42.891,857.2503577 +Guinea,1987,5650262,Africa,45.552,805.5724718 +Guinea,1992,6990574,Africa,48.576,794.3484384 +Guinea,1997,8048834,Africa,51.455,869.4497668 +Guinea,2002,8807818,Africa,53.676,945.5835837 +Guinea,2007,9947814,Africa,56.007,942.6542111 +Guinea-Bissau,1952,580653,Africa,32.5,299.850319 +Guinea-Bissau,1957,601095,Africa,33.489,431.7904566 +Guinea-Bissau,1962,627820,Africa,34.488,522.0343725 +Guinea-Bissau,1967,601287,Africa,35.492,715.5806402 +Guinea-Bissau,1972,625361,Africa,36.486,820.2245876 +Guinea-Bissau,1977,745228,Africa,37.465,764.7259628 +Guinea-Bissau,1982,825987,Africa,39.327,838.1239671 +Guinea-Bissau,1987,927524,Africa,41.245,736.4153921 +Guinea-Bissau,1992,1050938,Africa,43.266,745.5398706 +Guinea-Bissau,1997,1193708,Africa,44.873,796.6644681 +Guinea-Bissau,2002,1332459,Africa,45.504,575.7047176 +Guinea-Bissau,2007,1472041,Africa,46.388,579.231743 +Haiti,1952,3201488,Americas,37.579,1840.366939 +Haiti,1957,3507701,Americas,40.696,1726.887882 +Haiti,1962,3880130,Americas,43.59,1796.589032 +Haiti,1967,4318137,Americas,46.243,1452.057666 +Haiti,1972,4698301,Americas,48.042,1654.456946 +Haiti,1977,4908554,Americas,49.923,1874.298931 +Haiti,1982,5198399,Americas,51.461,2011.159549 +Haiti,1987,5756203,Americas,53.636,1823.015995 +Haiti,1992,6326682,Americas,55.089,1456.309517 +Haiti,1997,6913545,Americas,56.671,1341.726931 +Haiti,2002,7607651,Americas,58.137,1270.364932 +Haiti,2007,8502814,Americas,60.916,1201.637154 +Honduras,1952,1517453,Americas,41.912,2194.926204 +Honduras,1957,1770390,Americas,44.665,2220.487682 +Honduras,1962,2090162,Americas,48.041,2291.156835 +Honduras,1967,2500689,Americas,50.924,2538.269358 +Honduras,1972,2965146,Americas,53.884,2529.842345 +Honduras,1977,3055235,Americas,57.402,3203.208066 +Honduras,1982,3669448,Americas,60.909,3121.760794 +Honduras,1987,4372203,Americas,64.492,3023.096699 +Honduras,1992,5077347,Americas,66.399,3081.694603 +Honduras,1997,5867957,Americas,67.659,3160.454906 +Honduras,2002,6677328,Americas,68.565,3099.72866 +Honduras,2007,7483763,Americas,70.198,3548.330846 +Hong Kong China,1952,2125900,Asia,60.96,3054.421209 +Hong Kong China,1957,2736300,Asia,64.75,3629.076457 +Hong Kong China,1962,3305200,Asia,67.65,4692.648272 +Hong Kong China,1967,3722800,Asia,70,6197.962814 +Hong Kong China,1972,4115700,Asia,72,8315.928145 +Hong Kong China,1977,4583700,Asia,73.6,11186.14125 +Hong Kong China,1982,5264500,Asia,75.45,14560.53051 +Hong Kong China,1987,5584510,Asia,76.2,20038.47269 +Hong Kong China,1992,5829696,Asia,77.601,24757.60301 +Hong Kong China,1997,6495918,Asia,80,28377.63219 +Hong Kong China,2002,6762476,Asia,81.495,30209.01516 +Hong Kong China,2007,6980412,Asia,82.208,39724.97867 +Hungary,1952,9504000,Europe,64.03,5263.673816 +Hungary,1957,9839000,Europe,66.41,6040.180011 +Hungary,1962,10063000,Europe,67.96,7550.359877 +Hungary,1967,10223422,Europe,69.5,9326.64467 +Hungary,1972,10394091,Europe,69.76,10168.65611 +Hungary,1977,10637171,Europe,69.95,11674.83737 +Hungary,1982,10705535,Europe,69.39,12545.99066 +Hungary,1987,10612740,Europe,69.58,12986.47998 +Hungary,1992,10348684,Europe,69.17,10535.62855 +Hungary,1997,10244684,Europe,71.04,11712.7768 +Hungary,2002,10083313,Europe,72.59,14843.93556 +Hungary,2007,9956108,Europe,73.338,18008.94444 +Iceland,1952,147962,Europe,72.49,7267.688428 +Iceland,1957,165110,Europe,73.47,9244.001412 +Iceland,1962,182053,Europe,73.68,10350.15906 +Iceland,1967,198676,Europe,73.73,13319.89568 +Iceland,1972,209275,Europe,74.46,15798.06362 +Iceland,1977,221823,Europe,76.11,19654.96247 +Iceland,1982,233997,Europe,76.99,23269.6075 +Iceland,1987,244676,Europe,77.23,26923.20628 +Iceland,1992,259012,Europe,78.77,25144.39201 +Iceland,1997,271192,Europe,78.95,28061.09966 +Iceland,2002,288030,Europe,80.5,31163.20196 +Iceland,2007,301931,Europe,81.757,36180.78919 +India,1952,3.72e+08,Asia,37.373,546.5657493 +India,1957,4.09e+08,Asia,40.249,590.061996 +India,1962,4.54e+08,Asia,43.605,658.3471509 +India,1967,5.06e+08,Asia,47.193,700.7706107 +India,1972,5.67e+08,Asia,50.651,724.032527 +India,1977,6.34e+08,Asia,54.208,813.337323 +India,1982,7.08e+08,Asia,56.596,855.7235377 +India,1987,7.88e+08,Asia,58.553,976.5126756 +India,1992,8.72e+08,Asia,60.223,1164.406809 +India,1997,9.59e+08,Asia,61.765,1458.817442 +India,2002,1034172547,Asia,62.879,1746.769454 +India,2007,1110396331,Asia,64.698,2452.210407 +Indonesia,1952,82052000,Asia,37.468,749.6816546 +Indonesia,1957,90124000,Asia,39.918,858.9002707 +Indonesia,1962,99028000,Asia,42.518,849.2897701 +Indonesia,1967,109343000,Asia,45.964,762.4317721 +Indonesia,1972,121282000,Asia,49.203,1111.107907 +Indonesia,1977,136725000,Asia,52.702,1382.702056 +Indonesia,1982,153343000,Asia,56.159,1516.872988 +Indonesia,1987,169276000,Asia,60.137,1748.356961 +Indonesia,1992,184816000,Asia,62.681,2383.140898 +Indonesia,1997,199278000,Asia,66.041,3119.335603 +Indonesia,2002,211060000,Asia,68.588,2873.91287 +Indonesia,2007,223547000,Asia,70.65,3540.651564 +Iran,1952,17272000,Asia,44.869,3035.326002 +Iran,1957,19792000,Asia,47.181,3290.257643 +Iran,1962,22874000,Asia,49.325,4187.329802 +Iran,1967,26538000,Asia,52.469,5906.731805 +Iran,1972,30614000,Asia,55.234,9613.818607 +Iran,1977,35480679,Asia,57.702,11888.59508 +Iran,1982,43072751,Asia,59.62,7608.334602 +Iran,1987,51889696,Asia,63.04,6642.881371 +Iran,1992,60397973,Asia,65.742,7235.653188 +Iran,1997,63327987,Asia,68.042,8263.590301 +Iran,2002,66907826,Asia,69.451,9240.761975 +Iran,2007,69453570,Asia,70.964,11605.71449 +Iraq,1952,5441766,Asia,45.32,4129.766056 +Iraq,1957,6248643,Asia,48.437,6229.333562 +Iraq,1962,7240260,Asia,51.457,8341.737815 +Iraq,1967,8519282,Asia,54.459,8931.459811 +Iraq,1972,10061506,Asia,56.95,9576.037596 +Iraq,1977,11882916,Asia,60.413,14688.23507 +Iraq,1982,14173318,Asia,62.038,14517.90711 +Iraq,1987,16543189,Asia,65.044,11643.57268 +Iraq,1992,17861905,Asia,59.461,3745.640687 +Iraq,1997,20775703,Asia,58.811,3076.239795 +Iraq,2002,24001816,Asia,57.046,4390.717312 +Iraq,2007,27499638,Asia,59.545,4471.061906 +Ireland,1952,2952156,Europe,66.91,5210.280328 +Ireland,1957,2878220,Europe,68.9,5599.077872 +Ireland,1962,2830000,Europe,70.29,6631.597314 +Ireland,1967,2900100,Europe,71.08,7655.568963 +Ireland,1972,3024400,Europe,71.28,9530.772896 +Ireland,1977,3271900,Europe,72.03,11150.98113 +Ireland,1982,3480000,Europe,73.1,12618.32141 +Ireland,1987,3539900,Europe,74.36,13872.86652 +Ireland,1992,3557761,Europe,75.467,17558.81555 +Ireland,1997,3667233,Europe,76.122,24521.94713 +Ireland,2002,3879155,Europe,77.783,34077.04939 +Ireland,2007,4109086,Europe,78.885,40675.99635 +Israel,1952,1620914,Asia,65.39,4086.522128 +Israel,1957,1944401,Asia,67.84,5385.278451 +Israel,1962,2310904,Asia,69.39,7105.630706 +Israel,1967,2693585,Asia,70.75,8393.741404 +Israel,1972,3095893,Asia,71.63,12786.93223 +Israel,1977,3495918,Asia,73.06,13306.61921 +Israel,1982,3858421,Asia,74.45,15367.0292 +Israel,1987,4203148,Asia,75.6,17122.47986 +Israel,1992,4936550,Asia,76.93,18051.52254 +Israel,1997,5531387,Asia,78.269,20896.60924 +Israel,2002,6029529,Asia,79.696,21905.59514 +Israel,2007,6426679,Asia,80.745,25523.2771 +Italy,1952,47666000,Europe,65.94,4931.404155 +Italy,1957,49182000,Europe,67.81,6248.656232 +Italy,1962,50843200,Europe,69.24,8243.58234 +Italy,1967,52667100,Europe,71.06,10022.40131 +Italy,1972,54365564,Europe,72.19,12269.27378 +Italy,1977,56059245,Europe,73.48,14255.98475 +Italy,1982,56535636,Europe,74.98,16537.4835 +Italy,1987,56729703,Europe,76.42,19207.23482 +Italy,1992,56840847,Europe,77.44,22013.64486 +Italy,1997,57479469,Europe,78.82,24675.02446 +Italy,2002,57926999,Europe,80.24,27968.09817 +Italy,2007,58147733,Europe,80.546,28569.7197 +Jamaica,1952,1426095,Americas,58.53,2898.530881 +Jamaica,1957,1535090,Americas,62.61,4756.525781 +Jamaica,1962,1665128,Americas,65.61,5246.107524 +Jamaica,1967,1861096,Americas,67.51,6124.703451 +Jamaica,1972,1997616,Americas,69,7433.889293 +Jamaica,1977,2156814,Americas,70.11,6650.195573 +Jamaica,1982,2298309,Americas,71.21,6068.05135 +Jamaica,1987,2326606,Americas,71.77,6351.237495 +Jamaica,1992,2378618,Americas,71.766,7404.923685 +Jamaica,1997,2531311,Americas,72.262,7121.924704 +Jamaica,2002,2664659,Americas,72.047,6994.774861 +Jamaica,2007,2780132,Americas,72.567,7320.880262 +Japan,1952,86459025,Asia,63.03,3216.956347 +Japan,1957,91563009,Asia,65.5,4317.694365 +Japan,1962,95831757,Asia,68.73,6576.649461 +Japan,1967,100825279,Asia,71.43,9847.788607 +Japan,1972,107188273,Asia,73.42,14778.78636 +Japan,1977,113872473,Asia,75.38,16610.37701 +Japan,1982,118454974,Asia,77.11,19384.10571 +Japan,1987,122091325,Asia,78.67,22375.94189 +Japan,1992,124329269,Asia,79.36,26824.89511 +Japan,1997,125956499,Asia,80.69,28816.58499 +Japan,2002,127065841,Asia,82,28604.5919 +Japan,2007,127467972,Asia,82.603,31656.06806 +Jordan,1952,607914,Asia,43.158,1546.907807 +Jordan,1957,746559,Asia,45.669,1886.080591 +Jordan,1962,933559,Asia,48.126,2348.009158 +Jordan,1967,1255058,Asia,51.629,2741.796252 +Jordan,1972,1613551,Asia,56.528,2110.856309 +Jordan,1977,1937652,Asia,61.134,2852.351568 +Jordan,1982,2347031,Asia,63.739,4161.415959 +Jordan,1987,2820042,Asia,65.869,4448.679912 +Jordan,1992,3867409,Asia,68.015,3431.593647 +Jordan,1997,4526235,Asia,69.772,3645.379572 +Jordan,2002,5307470,Asia,71.263,3844.917194 +Jordan,2007,6053193,Asia,72.535,4519.461171 +Kenya,1952,6464046,Africa,42.27,853.540919 +Kenya,1957,7454779,Africa,44.686,944.4383152 +Kenya,1962,8678557,Africa,47.949,896.9663732 +Kenya,1967,10191512,Africa,50.654,1056.736457 +Kenya,1972,12044785,Africa,53.559,1222.359968 +Kenya,1977,14500404,Africa,56.155,1267.613204 +Kenya,1982,17661452,Africa,58.766,1348.225791 +Kenya,1987,21198082,Africa,59.339,1361.936856 +Kenya,1992,25020539,Africa,59.285,1341.921721 +Kenya,1997,28263827,Africa,54.407,1360.485021 +Kenya,2002,31386842,Africa,50.992,1287.514732 +Kenya,2007,35610177,Africa,54.11,1463.249282 +Korea Dem. Rep.,1952,8865488,Asia,50.056,1088.277758 +Korea Dem. Rep.,1957,9411381,Asia,54.081,1571.134655 +Korea Dem. Rep.,1962,10917494,Asia,56.656,1621.693598 +Korea Dem. Rep.,1967,12617009,Asia,59.942,2143.540609 +Korea Dem. Rep.,1972,14781241,Asia,63.983,3701.621503 +Korea Dem. Rep.,1977,16325320,Asia,67.159,4106.301249 +Korea Dem. Rep.,1982,17647518,Asia,69.1,4106.525293 +Korea Dem. Rep.,1987,19067554,Asia,70.647,4106.492315 +Korea Dem. Rep.,1992,20711375,Asia,69.978,3726.063507 +Korea Dem. Rep.,1997,21585105,Asia,67.727,1690.756814 +Korea Dem. Rep.,2002,22215365,Asia,66.662,1646.758151 +Korea Dem. Rep.,2007,23301725,Asia,67.297,1593.06548 +Korea Rep.,1952,20947571,Asia,47.453,1030.592226 +Korea Rep.,1957,22611552,Asia,52.681,1487.593537 +Korea Rep.,1962,26420307,Asia,55.292,1536.344387 +Korea Rep.,1967,30131000,Asia,57.716,2029.228142 +Korea Rep.,1972,33505000,Asia,62.612,3030.87665 +Korea Rep.,1977,36436000,Asia,64.766,4657.22102 +Korea Rep.,1982,39326000,Asia,67.123,5622.942464 +Korea Rep.,1987,41622000,Asia,69.81,8533.088805 +Korea Rep.,1992,43805450,Asia,72.244,12104.27872 +Korea Rep.,1997,46173816,Asia,74.647,15993.52796 +Korea Rep.,2002,47969150,Asia,77.045,19233.98818 +Korea Rep.,2007,49044790,Asia,78.623,23348.13973 +Kuwait,1952,160000,Asia,55.565,108382.3529 +Kuwait,1957,212846,Asia,58.033,113523.1329 +Kuwait,1962,358266,Asia,60.47,95458.11176 +Kuwait,1967,575003,Asia,64.624,80894.88326 +Kuwait,1972,841934,Asia,67.712,109347.867 +Kuwait,1977,1140357,Asia,69.343,59265.47714 +Kuwait,1982,1497494,Asia,71.309,31354.03573 +Kuwait,1987,1891487,Asia,74.174,28118.42998 +Kuwait,1992,1418095,Asia,75.19,34932.91959 +Kuwait,1997,1765345,Asia,76.156,40300.61996 +Kuwait,2002,2111561,Asia,76.904,35110.10566 +Kuwait,2007,2505559,Asia,77.588,47306.98978 +Lebanon,1952,1439529,Asia,55.928,4834.804067 +Lebanon,1957,1647412,Asia,59.489,6089.786934 +Lebanon,1962,1886848,Asia,62.094,5714.560611 +Lebanon,1967,2186894,Asia,63.87,6006.983042 +Lebanon,1972,2680018,Asia,65.421,7486.384341 +Lebanon,1977,3115787,Asia,66.099,8659.696836 +Lebanon,1982,3086876,Asia,66.983,7640.519521 +Lebanon,1987,3089353,Asia,67.926,5377.091329 +Lebanon,1992,3219994,Asia,69.292,6890.806854 +Lebanon,1997,3430388,Asia,70.265,8754.96385 +Lebanon,2002,3677780,Asia,71.028,9313.93883 +Lebanon,2007,3921278,Asia,71.993,10461.05868 +Lesotho,1952,748747,Africa,42.138,298.8462121 +Lesotho,1957,813338,Africa,45.047,335.9971151 +Lesotho,1962,893143,Africa,47.747,411.8006266 +Lesotho,1967,996380,Africa,48.492,498.6390265 +Lesotho,1972,1116779,Africa,49.767,496.5815922 +Lesotho,1977,1251524,Africa,52.208,745.3695408 +Lesotho,1982,1411807,Africa,55.078,797.2631074 +Lesotho,1987,1599200,Africa,57.18,773.9932141 +Lesotho,1992,1803195,Africa,59.685,977.4862725 +Lesotho,1997,1982823,Africa,55.558,1186.147994 +Lesotho,2002,2046772,Africa,44.593,1275.184575 +Lesotho,2007,2012649,Africa,42.592,1569.331442 +Liberia,1952,863308,Africa,38.48,575.5729961 +Liberia,1957,975950,Africa,39.486,620.9699901 +Liberia,1962,1112796,Africa,40.502,634.1951625 +Liberia,1967,1279406,Africa,41.536,713.6036483 +Liberia,1972,1482628,Africa,42.614,803.0054535 +Liberia,1977,1703617,Africa,43.764,640.3224383 +Liberia,1982,1956875,Africa,44.852,572.1995694 +Liberia,1987,2269414,Africa,46.027,506.1138573 +Liberia,1992,1912974,Africa,40.802,636.6229191 +Liberia,1997,2200725,Africa,42.221,609.1739508 +Liberia,2002,2814651,Africa,43.753,531.4823679 +Liberia,2007,3193942,Africa,45.678,414.5073415 +Libya,1952,1019729,Africa,42.723,2387.54806 +Libya,1957,1201578,Africa,45.289,3448.284395 +Libya,1962,1441863,Africa,47.808,6757.030816 +Libya,1967,1759224,Africa,50.227,18772.75169 +Libya,1972,2183877,Africa,52.773,21011.49721 +Libya,1977,2721783,Africa,57.442,21951.21176 +Libya,1982,3344074,Africa,62.155,17364.27538 +Libya,1987,3799845,Africa,66.234,11770.5898 +Libya,1992,4364501,Africa,68.755,9640.138501 +Libya,1997,4759670,Africa,71.555,9467.446056 +Libya,2002,5368585,Africa,72.737,9534.677467 +Libya,2007,6036914,Africa,73.952,12057.49928 +Madagascar,1952,4762912,Africa,36.681,1443.011715 +Madagascar,1957,5181679,Africa,38.865,1589.20275 +Madagascar,1962,5703324,Africa,40.848,1643.38711 +Madagascar,1967,6334556,Africa,42.881,1634.047282 +Madagascar,1972,7082430,Africa,44.851,1748.562982 +Madagascar,1977,8007166,Africa,46.881,1544.228586 +Madagascar,1982,9171477,Africa,48.969,1302.878658 +Madagascar,1987,10568642,Africa,49.35,1155.441948 +Madagascar,1992,12210395,Africa,52.214,1040.67619 +Madagascar,1997,14165114,Africa,54.978,986.2958956 +Madagascar,2002,16473477,Africa,57.286,894.6370822 +Madagascar,2007,19167654,Africa,59.443,1044.770126 +Malawi,1952,2917802,Africa,36.256,369.1650802 +Malawi,1957,3221238,Africa,37.207,416.3698064 +Malawi,1962,3628608,Africa,38.41,427.9010856 +Malawi,1967,4147252,Africa,39.487,495.5147806 +Malawi,1972,4730997,Africa,41.766,584.6219709 +Malawi,1977,5637246,Africa,43.767,663.2236766 +Malawi,1982,6502825,Africa,45.642,632.8039209 +Malawi,1987,7824747,Africa,47.457,635.5173634 +Malawi,1992,10014249,Africa,49.42,563.2000145 +Malawi,1997,10419991,Africa,47.495,692.2758103 +Malawi,2002,11824495,Africa,45.009,665.4231186 +Malawi,2007,13327079,Africa,48.303,759.3499101 +Malaysia,1952,6748378,Asia,48.463,1831.132894 +Malaysia,1957,7739235,Asia,52.102,1810.066992 +Malaysia,1962,8906385,Asia,55.737,2036.884944 +Malaysia,1967,10154878,Asia,59.371,2277.742396 +Malaysia,1972,11441462,Asia,63.01,2849.09478 +Malaysia,1977,12845381,Asia,65.256,3827.921571 +Malaysia,1982,14441916,Asia,68,4920.355951 +Malaysia,1987,16331785,Asia,69.5,5249.802653 +Malaysia,1992,18319502,Asia,70.693,7277.912802 +Malaysia,1997,20476091,Asia,71.938,10132.90964 +Malaysia,2002,22662365,Asia,73.044,10206.97794 +Malaysia,2007,24821286,Asia,74.241,12451.6558 +Mali,1952,3838168,Africa,33.685,452.3369807 +Mali,1957,4241884,Africa,35.307,490.3821867 +Mali,1962,4690372,Africa,36.936,496.1743428 +Mali,1967,5212416,Africa,38.487,545.0098873 +Mali,1972,5828158,Africa,39.977,581.3688761 +Mali,1977,6491649,Africa,41.714,686.3952693 +Mali,1982,6998256,Africa,43.916,618.0140641 +Mali,1987,7634008,Africa,46.364,684.1715576 +Mali,1992,8416215,Africa,48.388,739.014375 +Mali,1997,9384984,Africa,49.903,790.2579846 +Mali,2002,10580176,Africa,51.818,951.4097518 +Mali,2007,12031795,Africa,54.467,1042.581557 +Mauritania,1952,1022556,Africa,40.543,743.1159097 +Mauritania,1957,1076852,Africa,42.338,846.1202613 +Mauritania,1962,1146757,Africa,44.248,1055.896036 +Mauritania,1967,1230542,Africa,46.289,1421.145193 +Mauritania,1972,1332786,Africa,48.437,1586.851781 +Mauritania,1977,1456688,Africa,50.852,1497.492223 +Mauritania,1982,1622136,Africa,53.599,1481.150189 +Mauritania,1987,1841240,Africa,56.145,1421.603576 +Mauritania,1992,2119465,Africa,58.333,1361.369784 +Mauritania,1997,2444741,Africa,60.43,1483.136136 +Mauritania,2002,2828858,Africa,62.247,1579.019543 +Mauritania,2007,3270065,Africa,64.164,1803.151496 +Mauritius,1952,516556,Africa,50.986,1967.955707 +Mauritius,1957,609816,Africa,58.089,2034.037981 +Mauritius,1962,701016,Africa,60.246,2529.067487 +Mauritius,1967,789309,Africa,61.557,2475.387562 +Mauritius,1972,851334,Africa,62.944,2575.484158 +Mauritius,1977,913025,Africa,64.93,3710.982963 +Mauritius,1982,992040,Africa,66.711,3688.037739 +Mauritius,1987,1042663,Africa,68.74,4783.586903 +Mauritius,1992,1096202,Africa,69.745,6058.253846 +Mauritius,1997,1149818,Africa,70.736,7425.705295 +Mauritius,2002,1200206,Africa,71.954,9021.815894 +Mauritius,2007,1250882,Africa,72.801,10956.99112 +Mexico,1952,30144317,Americas,50.789,3478.125529 +Mexico,1957,35015548,Americas,55.19,4131.546641 +Mexico,1962,41121485,Americas,58.299,4581.609385 +Mexico,1967,47995559,Americas,60.11,5754.733883 +Mexico,1972,55984294,Americas,62.361,6809.40669 +Mexico,1977,63759976,Americas,65.032,7674.929108 +Mexico,1982,71640904,Americas,67.405,9611.147541 +Mexico,1987,80122492,Americas,69.498,8688.156003 +Mexico,1992,88111030,Americas,71.455,9472.384295 +Mexico,1997,95895146,Americas,73.67,9767.29753 +Mexico,2002,102479927,Americas,74.902,10742.44053 +Mexico,2007,108700891,Americas,76.195,11977.57496 +Mongolia,1952,800663,Asia,42.244,786.5668575 +Mongolia,1957,882134,Asia,45.248,912.6626085 +Mongolia,1962,1010280,Asia,48.251,1056.353958 +Mongolia,1967,1149500,Asia,51.253,1226.04113 +Mongolia,1972,1320500,Asia,53.754,1421.741975 +Mongolia,1977,1528000,Asia,55.491,1647.511665 +Mongolia,1982,1756032,Asia,57.489,2000.603139 +Mongolia,1987,2015133,Asia,60.222,2338.008304 +Mongolia,1992,2312802,Asia,61.271,1785.402016 +Mongolia,1997,2494803,Asia,63.625,1902.2521 +Mongolia,2002,2674234,Asia,65.033,2140.739323 +Mongolia,2007,2874127,Asia,66.803,3095.772271 +Montenegro,1952,413834,Europe,59.164,2647.585601 +Montenegro,1957,442829,Europe,61.448,3682.259903 +Montenegro,1962,474528,Europe,63.728,4649.593785 +Montenegro,1967,501035,Europe,67.178,5907.850937 +Montenegro,1972,527678,Europe,70.636,7778.414017 +Montenegro,1977,560073,Europe,73.066,9595.929905 +Montenegro,1982,562548,Europe,74.101,11222.58762 +Montenegro,1987,569473,Europe,74.865,11732.51017 +Montenegro,1992,621621,Europe,75.435,7003.339037 +Montenegro,1997,692651,Europe,75.445,6465.613349 +Montenegro,2002,720230,Europe,73.981,6557.194282 +Montenegro,2007,684736,Europe,74.543,9253.896111 +Morocco,1952,9939217,Africa,42.873,1688.20357 +Morocco,1957,11406350,Africa,45.423,1642.002314 +Morocco,1962,13056604,Africa,47.924,1566.353493 +Morocco,1967,14770296,Africa,50.335,1711.04477 +Morocco,1972,16660670,Africa,52.862,1930.194975 +Morocco,1977,18396941,Africa,55.73,2370.619976 +Morocco,1982,20198730,Africa,59.65,2702.620356 +Morocco,1987,22987397,Africa,62.677,2755.046991 +Morocco,1992,25798239,Africa,65.393,2948.047252 +Morocco,1997,28529501,Africa,67.66,2982.101858 +Morocco,2002,31167783,Africa,69.615,3258.495584 +Morocco,2007,33757175,Africa,71.164,3820.17523 +Mozambique,1952,6446316,Africa,31.286,468.5260381 +Mozambique,1957,7038035,Africa,33.779,495.5868333 +Mozambique,1962,7788944,Africa,36.161,556.6863539 +Mozambique,1967,8680909,Africa,38.113,566.6691539 +Mozambique,1972,9809596,Africa,40.328,724.9178037 +Mozambique,1977,11127868,Africa,42.495,502.3197334 +Mozambique,1982,12587223,Africa,42.795,462.2114149 +Mozambique,1987,12891952,Africa,42.861,389.8761846 +Mozambique,1992,13160731,Africa,44.284,410.8968239 +Mozambique,1997,16603334,Africa,46.344,472.3460771 +Mozambique,2002,18473780,Africa,44.026,633.6179466 +Mozambique,2007,19951656,Africa,42.082,823.6856205 +Myanmar,1952,20092996,Asia,36.319,331 +Myanmar,1957,21731844,Asia,41.905,350 +Myanmar,1962,23634436,Asia,45.108,388 +Myanmar,1967,25870271,Asia,49.379,349 +Myanmar,1972,28466390,Asia,53.07,357 +Myanmar,1977,31528087,Asia,56.059,371 +Myanmar,1982,34680442,Asia,58.056,424 +Myanmar,1987,38028578,Asia,58.339,385 +Myanmar,1992,40546538,Asia,59.32,347 +Myanmar,1997,43247867,Asia,60.328,415 +Myanmar,2002,45598081,Asia,59.908,611 +Myanmar,2007,47761980,Asia,62.069,944 +Namibia,1952,485831,Africa,41.725,2423.780443 +Namibia,1957,548080,Africa,45.226,2621.448058 +Namibia,1962,621392,Africa,48.386,3173.215595 +Namibia,1967,706640,Africa,51.159,3793.694753 +Namibia,1972,821782,Africa,53.867,3746.080948 +Namibia,1977,977026,Africa,56.437,3876.485958 +Namibia,1982,1099010,Africa,58.968,4191.100511 +Namibia,1987,1278184,Africa,60.835,3693.731337 +Namibia,1992,1554253,Africa,61.999,3804.537999 +Namibia,1997,1774766,Africa,58.909,3899.52426 +Namibia,2002,1972153,Africa,51.479,4072.324751 +Namibia,2007,2055080,Africa,52.906,4811.060429 +Nepal,1952,9182536,Asia,36.157,545.8657229 +Nepal,1957,9682338,Asia,37.686,597.9363558 +Nepal,1962,10332057,Asia,39.393,652.3968593 +Nepal,1967,11261690,Asia,41.472,676.4422254 +Nepal,1972,12412593,Asia,43.971,674.7881296 +Nepal,1977,13933198,Asia,46.748,694.1124398 +Nepal,1982,15796314,Asia,49.594,718.3730947 +Nepal,1987,17917180,Asia,52.537,775.6324501 +Nepal,1992,20326209,Asia,55.727,897.7403604 +Nepal,1997,23001113,Asia,59.426,1010.892138 +Nepal,2002,25873917,Asia,61.34,1057.206311 +Nepal,2007,28901790,Asia,63.785,1091.359778 +Netherlands,1952,10381988,Europe,72.13,8941.571858 +Netherlands,1957,11026383,Europe,72.99,11276.19344 +Netherlands,1962,11805689,Europe,73.23,12790.84956 +Netherlands,1967,12596822,Europe,73.82,15363.25136 +Netherlands,1972,13329874,Europe,73.75,18794.74567 +Netherlands,1977,13852989,Europe,75.24,21209.0592 +Netherlands,1982,14310401,Europe,76.05,21399.46046 +Netherlands,1987,14665278,Europe,76.83,23651.32361 +Netherlands,1992,15174244,Europe,77.42,26790.94961 +Netherlands,1997,15604464,Europe,78.03,30246.13063 +Netherlands,2002,16122830,Europe,78.53,33724.75778 +Netherlands,2007,16570613,Europe,79.762,36797.93332 +New Zealand,1952,1994794,Oceania,69.39,10556.57566 +New Zealand,1957,2229407,Oceania,70.26,12247.39532 +New Zealand,1962,2488550,Oceania,71.24,13175.678 +New Zealand,1967,2728150,Oceania,71.52,14463.91893 +New Zealand,1972,2929100,Oceania,71.89,16046.03728 +New Zealand,1977,3164900,Oceania,72.22,16233.7177 +New Zealand,1982,3210650,Oceania,73.84,17632.4104 +New Zealand,1987,3317166,Oceania,74.32,19007.19129 +New Zealand,1992,3437674,Oceania,76.33,18363.32494 +New Zealand,1997,3676187,Oceania,77.55,21050.41377 +New Zealand,2002,3908037,Oceania,79.11,23189.80135 +New Zealand,2007,4115771,Oceania,80.204,25185.00911 +Nicaragua,1952,1165790,Americas,42.314,3112.363948 +Nicaragua,1957,1358828,Americas,45.432,3457.415947 +Nicaragua,1962,1590597,Americas,48.632,3634.364406 +Nicaragua,1967,1865490,Americas,51.884,4643.393534 +Nicaragua,1972,2182908,Americas,55.151,4688.593267 +Nicaragua,1977,2554598,Americas,57.47,5486.371089 +Nicaragua,1982,2979423,Americas,59.298,3470.338156 +Nicaragua,1987,3344353,Americas,62.008,2955.984375 +Nicaragua,1992,4017939,Americas,65.843,2170.151724 +Nicaragua,1997,4609572,Americas,68.426,2253.023004 +Nicaragua,2002,5146848,Americas,70.836,2474.548819 +Nicaragua,2007,5675356,Americas,72.899,2749.320965 +Niger,1952,3379468,Africa,37.444,761.879376 +Niger,1957,3692184,Africa,38.598,835.5234025 +Niger,1962,4076008,Africa,39.487,997.7661127 +Niger,1967,4534062,Africa,40.118,1054.384891 +Niger,1972,5060262,Africa,40.546,954.2092363 +Niger,1977,5682086,Africa,41.291,808.8970728 +Niger,1982,6437188,Africa,42.598,909.7221354 +Niger,1987,7332638,Africa,44.555,668.3000228 +Niger,1992,8392818,Africa,47.391,581.182725 +Niger,1997,9666252,Africa,51.313,580.3052092 +Niger,2002,11140655,Africa,54.496,601.0745012 +Niger,2007,12894865,Africa,56.867,619.6768924 +Nigeria,1952,33119096,Africa,36.324,1077.281856 +Nigeria,1957,37173340,Africa,37.802,1100.592563 +Nigeria,1962,41871351,Africa,39.36,1150.927478 +Nigeria,1967,47287752,Africa,41.04,1014.514104 +Nigeria,1972,53740085,Africa,42.821,1698.388838 +Nigeria,1977,62209173,Africa,44.514,1981.951806 +Nigeria,1982,73039376,Africa,45.826,1576.97375 +Nigeria,1987,81551520,Africa,46.886,1385.029563 +Nigeria,1992,93364244,Africa,47.472,1619.848217 +Nigeria,1997,106207839,Africa,47.464,1624.941275 +Nigeria,2002,119901274,Africa,46.608,1615.286395 +Nigeria,2007,135031164,Africa,46.859,2013.977305 +Norway,1952,3327728,Europe,72.67,10095.42172 +Norway,1957,3491938,Europe,73.44,11653.97304 +Norway,1962,3638919,Europe,73.47,13450.40151 +Norway,1967,3786019,Europe,74.08,16361.87647 +Norway,1972,3933004,Europe,74.34,18965.05551 +Norway,1977,4043205,Europe,75.37,23311.34939 +Norway,1982,4114787,Europe,75.97,26298.63531 +Norway,1987,4186147,Europe,75.89,31540.9748 +Norway,1992,4286357,Europe,77.32,33965.66115 +Norway,1997,4405672,Europe,78.32,41283.16433 +Norway,2002,4535591,Europe,79.05,44683.97525 +Norway,2007,4627926,Europe,80.196,49357.19017 +Oman,1952,507833,Asia,37.578,1828.230307 +Oman,1957,561977,Asia,40.08,2242.746551 +Oman,1962,628164,Asia,43.165,2924.638113 +Oman,1967,714775,Asia,46.988,4720.942687 +Oman,1972,829050,Asia,52.143,10618.03855 +Oman,1977,1004533,Asia,57.367,11848.34392 +Oman,1982,1301048,Asia,62.728,12954.79101 +Oman,1987,1593882,Asia,67.734,18115.22313 +Oman,1992,1915208,Asia,71.197,18616.70691 +Oman,1997,2283635,Asia,72.499,19702.05581 +Oman,2002,2713462,Asia,74.193,19774.83687 +Oman,2007,3204897,Asia,75.64,22316.19287 +Pakistan,1952,41346560,Asia,43.436,684.5971438 +Pakistan,1957,46679944,Asia,45.557,747.0835292 +Pakistan,1962,53100671,Asia,47.67,803.3427418 +Pakistan,1967,60641899,Asia,49.8,942.4082588 +Pakistan,1972,69325921,Asia,51.929,1049.938981 +Pakistan,1977,78152686,Asia,54.043,1175.921193 +Pakistan,1982,91462088,Asia,56.158,1443.429832 +Pakistan,1987,105186881,Asia,58.245,1704.686583 +Pakistan,1992,120065004,Asia,60.838,1971.829464 +Pakistan,1997,135564834,Asia,61.818,2049.350521 +Pakistan,2002,153403524,Asia,63.61,2092.712441 +Pakistan,2007,169270617,Asia,65.483,2605.94758 +Panama,1952,940080,Americas,55.191,2480.380334 +Panama,1957,1063506,Americas,59.201,2961.800905 +Panama,1962,1215725,Americas,61.817,3536.540301 +Panama,1967,1405486,Americas,64.071,4421.009084 +Panama,1972,1616384,Americas,66.216,5364.249663 +Panama,1977,1839782,Americas,68.681,5351.912144 +Panama,1982,2036305,Americas,70.472,7009.601598 +Panama,1987,2253639,Americas,71.523,7034.779161 +Panama,1992,2484997,Americas,72.462,6618.74305 +Panama,1997,2734531,Americas,73.738,7113.692252 +Panama,2002,2990875,Americas,74.712,7356.031934 +Panama,2007,3242173,Americas,75.537,9809.185636 +Paraguay,1952,1555876,Americas,62.649,1952.308701 +Paraguay,1957,1770902,Americas,63.196,2046.154706 +Paraguay,1962,2009813,Americas,64.361,2148.027146 +Paraguay,1967,2287985,Americas,64.951,2299.376311 +Paraguay,1972,2614104,Americas,65.815,2523.337977 +Paraguay,1977,2984494,Americas,66.353,3248.373311 +Paraguay,1982,3366439,Americas,66.874,4258.503604 +Paraguay,1987,3886512,Americas,67.378,3998.875695 +Paraguay,1992,4483945,Americas,68.225,4196.411078 +Paraguay,1997,5154123,Americas,69.4,4247.400261 +Paraguay,2002,5884491,Americas,70.755,3783.674243 +Paraguay,2007,6667147,Americas,71.752,4172.838464 +Peru,1952,8025700,Americas,43.902,3758.523437 +Peru,1957,9146100,Americas,46.263,4245.256698 +Peru,1962,10516500,Americas,49.096,4957.037982 +Peru,1967,12132200,Americas,51.445,5788.09333 +Peru,1972,13954700,Americas,55.448,5937.827283 +Peru,1977,15990099,Americas,58.447,6281.290855 +Peru,1982,18125129,Americas,61.406,6434.501797 +Peru,1987,20195924,Americas,64.134,6360.943444 +Peru,1992,22430449,Americas,66.458,4446.380924 +Peru,1997,24748122,Americas,68.386,5838.347657 +Peru,2002,26769436,Americas,69.906,5909.020073 +Peru,2007,28674757,Americas,71.421,7408.905561 +Philippines,1952,22438691,Asia,47.752,1272.880995 +Philippines,1957,26072194,Asia,51.334,1547.944844 +Philippines,1962,30325264,Asia,54.757,1649.552153 +Philippines,1967,35356600,Asia,56.393,1814.12743 +Philippines,1972,40850141,Asia,58.065,1989.37407 +Philippines,1977,46850962,Asia,60.06,2373.204287 +Philippines,1982,53456774,Asia,62.082,2603.273765 +Philippines,1987,60017788,Asia,64.151,2189.634995 +Philippines,1992,67185766,Asia,66.458,2279.324017 +Philippines,1997,75012988,Asia,68.564,2536.534925 +Philippines,2002,82995088,Asia,70.303,2650.921068 +Philippines,2007,91077287,Asia,71.688,3190.481016 +Poland,1952,25730551,Europe,61.31,4029.329699 +Poland,1957,28235346,Europe,65.77,4734.253019 +Poland,1962,30329617,Europe,67.64,5338.752143 +Poland,1967,31785378,Europe,69.61,6557.152776 +Poland,1972,33039545,Europe,70.85,8006.506993 +Poland,1977,34621254,Europe,70.67,9508.141454 +Poland,1982,36227381,Europe,71.32,8451.531004 +Poland,1987,37740710,Europe,70.98,9082.351172 +Poland,1992,38370697,Europe,70.99,7738.881247 +Poland,1997,38654957,Europe,72.75,10159.58368 +Poland,2002,38625976,Europe,74.67,12002.23908 +Poland,2007,38518241,Europe,75.563,15389.92468 +Portugal,1952,8526050,Europe,59.82,3068.319867 +Portugal,1957,8817650,Europe,61.51,3774.571743 +Portugal,1962,9019800,Europe,64.39,4727.954889 +Portugal,1967,9103000,Europe,66.6,6361.517993 +Portugal,1972,8970450,Europe,69.26,9022.247417 +Portugal,1977,9662600,Europe,70.41,10172.48572 +Portugal,1982,9859650,Europe,72.77,11753.84291 +Portugal,1987,9915289,Europe,74.06,13039.30876 +Portugal,1992,9927680,Europe,74.86,16207.26663 +Portugal,1997,10156415,Europe,75.97,17641.03156 +Portugal,2002,10433867,Europe,77.29,19970.90787 +Portugal,2007,10642836,Europe,78.098,20509.64777 +Puerto Rico,1952,2227000,Americas,64.28,3081.959785 +Puerto Rico,1957,2260000,Americas,68.54,3907.156189 +Puerto Rico,1962,2448046,Americas,69.62,5108.34463 +Puerto Rico,1967,2648961,Americas,71.1,6929.277714 +Puerto Rico,1972,2847132,Americas,72.16,9123.041742 +Puerto Rico,1977,3080828,Americas,73.44,9770.524921 +Puerto Rico,1982,3279001,Americas,73.75,10330.98915 +Puerto Rico,1987,3444468,Americas,74.63,12281.34191 +Puerto Rico,1992,3585176,Americas,73.911,14641.58711 +Puerto Rico,1997,3759430,Americas,74.917,16999.4333 +Puerto Rico,2002,3859606,Americas,77.778,18855.60618 +Puerto Rico,2007,3942491,Americas,78.746,19328.70901 +Reunion,1952,257700,Africa,52.724,2718.885295 +Reunion,1957,308700,Africa,55.09,2769.451844 +Reunion,1962,358900,Africa,57.666,3173.72334 +Reunion,1967,414024,Africa,60.542,4021.175739 +Reunion,1972,461633,Africa,64.274,5047.658563 +Reunion,1977,492095,Africa,67.064,4319.804067 +Reunion,1982,517810,Africa,69.885,5267.219353 +Reunion,1987,562035,Africa,71.913,5303.377488 +Reunion,1992,622191,Africa,73.615,6101.255823 +Reunion,1997,684810,Africa,74.772,6071.941411 +Reunion,2002,743981,Africa,75.744,6316.1652 +Reunion,2007,798094,Africa,76.442,7670.122558 +Romania,1952,16630000,Europe,61.05,3144.613186 +Romania,1957,17829327,Europe,64.1,3943.370225 +Romania,1962,18680721,Europe,66.8,4734.997586 +Romania,1967,19284814,Europe,66.8,6470.866545 +Romania,1972,20662648,Europe,69.21,8011.414402 +Romania,1977,21658597,Europe,69.46,9356.39724 +Romania,1982,22356726,Europe,69.66,9605.314053 +Romania,1987,22686371,Europe,69.53,9696.273295 +Romania,1992,22797027,Europe,69.36,6598.409903 +Romania,1997,22562458,Europe,69.72,7346.547557 +Romania,2002,22404337,Europe,71.322,7885.360081 +Romania,2007,22276056,Europe,72.476,10808.47561 +Rwanda,1952,2534927,Africa,40,493.3238752 +Rwanda,1957,2822082,Africa,41.5,540.2893983 +Rwanda,1962,3051242,Africa,43,597.4730727 +Rwanda,1967,3451079,Africa,44.1,510.9637142 +Rwanda,1972,3992121,Africa,44.6,590.5806638 +Rwanda,1977,4657072,Africa,45,670.0806011 +Rwanda,1982,5507565,Africa,46.218,881.5706467 +Rwanda,1987,6349365,Africa,44.02,847.991217 +Rwanda,1992,7290203,Africa,23.599,737.0685949 +Rwanda,1997,7212583,Africa,36.087,589.9445051 +Rwanda,2002,7852401,Africa,43.413,785.6537648 +Rwanda,2007,8860588,Africa,46.242,863.0884639 +Sao Tome and Principe,1952,60011,Africa,46.471,879.5835855 +Sao Tome and Principe,1957,61325,Africa,48.945,860.7369026 +Sao Tome and Principe,1962,65345,Africa,51.893,1071.551119 +Sao Tome and Principe,1967,70787,Africa,54.425,1384.840593 +Sao Tome and Principe,1972,76595,Africa,56.48,1532.985254 +Sao Tome and Principe,1977,86796,Africa,58.55,1737.561657 +Sao Tome and Principe,1982,98593,Africa,60.351,1890.218117 +Sao Tome and Principe,1987,110812,Africa,61.728,1516.525457 +Sao Tome and Principe,1992,125911,Africa,62.742,1428.777814 +Sao Tome and Principe,1997,145608,Africa,63.306,1339.076036 +Sao Tome and Principe,2002,170372,Africa,64.337,1353.09239 +Sao Tome and Principe,2007,199579,Africa,65.528,1598.435089 +Saudi Arabia,1952,4005677,Asia,39.875,6459.554823 +Saudi Arabia,1957,4419650,Asia,42.868,8157.591248 +Saudi Arabia,1962,4943029,Asia,45.914,11626.41975 +Saudi Arabia,1967,5618198,Asia,49.901,16903.04886 +Saudi Arabia,1972,6472756,Asia,53.886,24837.42865 +Saudi Arabia,1977,8128505,Asia,58.69,34167.7626 +Saudi Arabia,1982,11254672,Asia,63.012,33693.17525 +Saudi Arabia,1987,14619745,Asia,66.295,21198.26136 +Saudi Arabia,1992,16945857,Asia,68.768,24841.61777 +Saudi Arabia,1997,21229759,Asia,70.533,20586.69019 +Saudi Arabia,2002,24501530,Asia,71.626,19014.54118 +Saudi Arabia,2007,27601038,Asia,72.777,21654.83194 +Senegal,1952,2755589,Africa,37.278,1450.356983 +Senegal,1957,3054547,Africa,39.329,1567.653006 +Senegal,1962,3430243,Africa,41.454,1654.988723 +Senegal,1967,3965841,Africa,43.563,1612.404632 +Senegal,1972,4588696,Africa,45.815,1597.712056 +Senegal,1977,5260855,Africa,48.879,1561.769116 +Senegal,1982,6147783,Africa,52.379,1518.479984 +Senegal,1987,7171347,Africa,55.769,1441.72072 +Senegal,1992,8307920,Africa,58.196,1367.899369 +Senegal,1997,9535314,Africa,60.187,1392.368347 +Senegal,2002,10870037,Africa,61.6,1519.635262 +Senegal,2007,12267493,Africa,63.062,1712.472136 +Serbia,1952,6860147,Europe,57.996,3581.459448 +Serbia,1957,7271135,Europe,61.685,4981.090891 +Serbia,1962,7616060,Europe,64.531,6289.629157 +Serbia,1967,7971222,Europe,66.914,7991.707066 +Serbia,1972,8313288,Europe,68.7,10522.06749 +Serbia,1977,8686367,Europe,70.3,12980.66956 +Serbia,1982,9032824,Europe,70.162,15181.0927 +Serbia,1987,9230783,Europe,71.218,15870.87851 +Serbia,1992,9826397,Europe,71.659,9325.068238 +Serbia,1997,10336594,Europe,72.232,7914.320304 +Serbia,2002,10111559,Europe,73.213,7236.075251 +Serbia,2007,10150265,Europe,74.002,9786.534714 +Sierra Leone,1952,2143249,Africa,30.331,879.7877358 +Sierra Leone,1957,2295678,Africa,31.57,1004.484437 +Sierra Leone,1962,2467895,Africa,32.767,1116.639877 +Sierra Leone,1967,2662190,Africa,34.113,1206.043465 +Sierra Leone,1972,2879013,Africa,35.4,1353.759762 +Sierra Leone,1977,3140897,Africa,36.788,1348.285159 +Sierra Leone,1982,3464522,Africa,38.445,1465.010784 +Sierra Leone,1987,3868905,Africa,40.006,1294.447788 +Sierra Leone,1992,4260884,Africa,38.333,1068.696278 +Sierra Leone,1997,4578212,Africa,39.897,574.6481576 +Sierra Leone,2002,5359092,Africa,41.012,699.489713 +Sierra Leone,2007,6144562,Africa,42.568,862.5407561 +Singapore,1952,1127000,Asia,60.396,2315.138227 +Singapore,1957,1445929,Asia,63.179,2843.104409 +Singapore,1962,1750200,Asia,65.798,3674.735572 +Singapore,1967,1977600,Asia,67.946,4977.41854 +Singapore,1972,2152400,Asia,69.521,8597.756202 +Singapore,1977,2325300,Asia,70.795,11210.08948 +Singapore,1982,2651869,Asia,71.76,15169.16112 +Singapore,1987,2794552,Asia,73.56,18861.53081 +Singapore,1992,3235865,Asia,75.788,24769.8912 +Singapore,1997,3802309,Asia,77.158,33519.4766 +Singapore,2002,4197776,Asia,78.77,36023.1054 +Singapore,2007,4553009,Asia,79.972,47143.17964 +Slovak Republic,1952,3558137,Europe,64.36,5074.659104 +Slovak Republic,1957,3844277,Europe,67.45,6093.26298 +Slovak Republic,1962,4237384,Europe,70.33,7481.107598 +Slovak Republic,1967,4442238,Europe,70.98,8412.902397 +Slovak Republic,1972,4593433,Europe,70.35,9674.167626 +Slovak Republic,1977,4827803,Europe,70.45,10922.66404 +Slovak Republic,1982,5048043,Europe,70.8,11348.54585 +Slovak Republic,1987,5199318,Europe,71.08,12037.26758 +Slovak Republic,1992,5302888,Europe,71.38,9498.467723 +Slovak Republic,1997,5383010,Europe,72.71,12126.23065 +Slovak Republic,2002,5410052,Europe,73.8,13638.77837 +Slovak Republic,2007,5447502,Europe,74.663,18678.31435 +Slovenia,1952,1489518,Europe,65.57,4215.041741 +Slovenia,1957,1533070,Europe,67.85,5862.276629 +Slovenia,1962,1582962,Europe,69.15,7402.303395 +Slovenia,1967,1646912,Europe,69.18,9405.489397 +Slovenia,1972,1694510,Europe,69.82,12383.4862 +Slovenia,1977,1746919,Europe,70.97,15277.03017 +Slovenia,1982,1861252,Europe,71.063,17866.72175 +Slovenia,1987,1945870,Europe,72.25,18678.53492 +Slovenia,1992,1999210,Europe,73.64,14214.71681 +Slovenia,1997,2011612,Europe,75.13,17161.10735 +Slovenia,2002,2011497,Europe,76.66,20660.01936 +Slovenia,2007,2009245,Europe,77.926,25768.25759 +Somalia,1952,2526994,Africa,32.978,1135.749842 +Somalia,1957,2780415,Africa,34.977,1258.147413 +Somalia,1962,3080153,Africa,36.981,1369.488336 +Somalia,1967,3428839,Africa,38.977,1284.73318 +Somalia,1972,3840161,Africa,40.973,1254.576127 +Somalia,1977,4353666,Africa,41.974,1450.992513 +Somalia,1982,5828892,Africa,42.955,1176.807031 +Somalia,1987,6921858,Africa,44.501,1093.244963 +Somalia,1992,6099799,Africa,39.658,926.9602964 +Somalia,1997,6633514,Africa,43.795,930.5964284 +Somalia,2002,7753310,Africa,45.936,882.0818218 +Somalia,2007,9118773,Africa,48.159,926.1410683 +South Africa,1952,14264935,Africa,45.009,4725.295531 +South Africa,1957,16151549,Africa,47.985,5487.104219 +South Africa,1962,18356657,Africa,49.951,5768.729717 +South Africa,1967,20997321,Africa,51.927,7114.477971 +South Africa,1972,23935810,Africa,53.696,7765.962636 +South Africa,1977,27129932,Africa,55.527,8028.651439 +South Africa,1982,31140029,Africa,58.161,8568.266228 +South Africa,1987,35933379,Africa,60.834,7825.823398 +South Africa,1992,39964159,Africa,61.888,7225.069258 +South Africa,1997,42835005,Africa,60.236,7479.188244 +South Africa,2002,44433622,Africa,53.365,7710.946444 +South Africa,2007,43997828,Africa,49.339,9269.657808 +Spain,1952,28549870,Europe,64.94,3834.034742 +Spain,1957,29841614,Europe,66.66,4564.80241 +Spain,1962,31158061,Europe,69.69,5693.843879 +Spain,1967,32850275,Europe,71.44,7993.512294 +Spain,1972,34513161,Europe,73.06,10638.75131 +Spain,1977,36439000,Europe,74.39,13236.92117 +Spain,1982,37983310,Europe,76.3,13926.16997 +Spain,1987,38880702,Europe,76.9,15764.98313 +Spain,1992,39549438,Europe,77.57,18603.06452 +Spain,1997,39855442,Europe,78.77,20445.29896 +Spain,2002,40152517,Europe,79.78,24835.47166 +Spain,2007,40448191,Europe,80.941,28821.0637 +Sri Lanka,1952,7982342,Asia,57.593,1083.53203 +Sri Lanka,1957,9128546,Asia,61.456,1072.546602 +Sri Lanka,1962,10421936,Asia,62.192,1074.47196 +Sri Lanka,1967,11737396,Asia,64.266,1135.514326 +Sri Lanka,1972,13016733,Asia,65.042,1213.39553 +Sri Lanka,1977,14116836,Asia,65.949,1348.775651 +Sri Lanka,1982,15410151,Asia,68.757,1648.079789 +Sri Lanka,1987,16495304,Asia,69.011,1876.766827 +Sri Lanka,1992,17587060,Asia,70.379,2153.739222 +Sri Lanka,1997,18698655,Asia,70.457,2664.477257 +Sri Lanka,2002,19576783,Asia,70.815,3015.378833 +Sri Lanka,2007,20378239,Asia,72.396,3970.095407 +Sudan,1952,8504667,Africa,38.635,1615.991129 +Sudan,1957,9753392,Africa,39.624,1770.337074 +Sudan,1962,11183227,Africa,40.87,1959.593767 +Sudan,1967,12716129,Africa,42.858,1687.997641 +Sudan,1972,14597019,Africa,45.083,1659.652775 +Sudan,1977,17104986,Africa,47.8,2202.988423 +Sudan,1982,20367053,Africa,50.338,1895.544073 +Sudan,1987,24725960,Africa,51.744,1507.819159 +Sudan,1992,28227588,Africa,53.556,1492.197043 +Sudan,1997,32160729,Africa,55.373,1632.210764 +Sudan,2002,37090298,Africa,56.369,1993.398314 +Sudan,2007,42292929,Africa,58.556,2602.394995 +Swaziland,1952,290243,Africa,41.407,1148.376626 +Swaziland,1957,326741,Africa,43.424,1244.708364 +Swaziland,1962,370006,Africa,44.992,1856.182125 +Swaziland,1967,420690,Africa,46.633,2613.101665 +Swaziland,1972,480105,Africa,49.552,3364.836625 +Swaziland,1977,551425,Africa,52.537,3781.410618 +Swaziland,1982,649901,Africa,55.561,3895.384018 +Swaziland,1987,779348,Africa,57.678,3984.839812 +Swaziland,1992,962344,Africa,58.474,3553.0224 +Swaziland,1997,1054486,Africa,54.289,3876.76846 +Swaziland,2002,1130269,Africa,43.869,4128.116943 +Swaziland,2007,1133066,Africa,39.613,4513.480643 +Sweden,1952,7124673,Europe,71.86,8527.844662 +Sweden,1957,7363802,Europe,72.49,9911.878226 +Sweden,1962,7561588,Europe,73.37,12329.44192 +Sweden,1967,7867931,Europe,74.16,15258.29697 +Sweden,1972,8122293,Europe,74.72,17832.02464 +Sweden,1977,8251648,Europe,75.44,18855.72521 +Sweden,1982,8325260,Europe,76.42,20667.38125 +Sweden,1987,8421403,Europe,77.19,23586.92927 +Sweden,1992,8718867,Europe,78.16,23880.01683 +Sweden,1997,8897619,Europe,79.39,25266.59499 +Sweden,2002,8954175,Europe,80.04,29341.63093 +Sweden,2007,9031088,Europe,80.884,33859.74835 +Switzerland,1952,4815000,Europe,69.62,14734.23275 +Switzerland,1957,5126000,Europe,70.56,17909.48973 +Switzerland,1962,5666000,Europe,71.32,20431.0927 +Switzerland,1967,6063000,Europe,72.77,22966.14432 +Switzerland,1972,6401400,Europe,73.78,27195.11304 +Switzerland,1977,6316424,Europe,75.39,26982.29052 +Switzerland,1982,6468126,Europe,76.21,28397.71512 +Switzerland,1987,6649942,Europe,77.41,30281.70459 +Switzerland,1992,6995447,Europe,78.03,31871.5303 +Switzerland,1997,7193761,Europe,79.37,32135.32301 +Switzerland,2002,7361757,Europe,80.62,34480.95771 +Switzerland,2007,7554661,Europe,81.701,37506.41907 +Syria,1952,3661549,Asia,45.883,1643.485354 +Syria,1957,4149908,Asia,48.284,2117.234893 +Syria,1962,4834621,Asia,50.305,2193.037133 +Syria,1967,5680812,Asia,53.655,1881.923632 +Syria,1972,6701172,Asia,57.296,2571.423014 +Syria,1977,7932503,Asia,61.195,3195.484582 +Syria,1982,9410494,Asia,64.59,3761.837715 +Syria,1987,11242847,Asia,66.974,3116.774285 +Syria,1992,13219062,Asia,69.249,3340.542768 +Syria,1997,15081016,Asia,71.527,4014.238972 +Syria,2002,17155814,Asia,73.053,4090.925331 +Syria,2007,19314747,Asia,74.143,4184.548089 +Taiwan,1952,8550362,Asia,58.5,1206.947913 +Taiwan,1957,10164215,Asia,62.4,1507.86129 +Taiwan,1962,11918938,Asia,65.2,1822.879028 +Taiwan,1967,13648692,Asia,67.5,2643.858681 +Taiwan,1972,15226039,Asia,69.39,4062.523897 +Taiwan,1977,16785196,Asia,70.59,5596.519826 +Taiwan,1982,18501390,Asia,72.16,7426.354774 +Taiwan,1987,19757799,Asia,73.4,11054.56175 +Taiwan,1992,20686918,Asia,74.26,15215.6579 +Taiwan,1997,21628605,Asia,75.25,20206.82098 +Taiwan,2002,22454239,Asia,76.99,23235.42329 +Taiwan,2007,23174294,Asia,78.4,28718.27684 +Tanzania,1952,8322925,Africa,41.215,716.6500721 +Tanzania,1957,9452826,Africa,42.974,698.5356073 +Tanzania,1962,10863958,Africa,44.246,722.0038073 +Tanzania,1967,12607312,Africa,45.757,848.2186575 +Tanzania,1972,14706593,Africa,47.62,915.9850592 +Tanzania,1977,17129565,Africa,49.919,962.4922932 +Tanzania,1982,19844382,Africa,50.608,874.2426069 +Tanzania,1987,23040630,Africa,51.535,831.8220794 +Tanzania,1992,26605473,Africa,50.44,825.682454 +Tanzania,1997,30686889,Africa,48.466,789.1862231 +Tanzania,2002,34593779,Africa,49.651,899.0742111 +Tanzania,2007,38139640,Africa,52.517,1107.482182 +Thailand,1952,21289402,Asia,50.848,757.7974177 +Thailand,1957,25041917,Asia,53.63,793.5774148 +Thailand,1962,29263397,Asia,56.061,1002.199172 +Thailand,1967,34024249,Asia,58.285,1295.46066 +Thailand,1972,39276153,Asia,60.405,1524.358936 +Thailand,1977,44148285,Asia,62.494,1961.224635 +Thailand,1982,48827160,Asia,64.597,2393.219781 +Thailand,1987,52910342,Asia,66.084,2982.653773 +Thailand,1992,56667095,Asia,67.298,4616.896545 +Thailand,1997,60216677,Asia,67.521,5852.625497 +Thailand,2002,62806748,Asia,68.564,5913.187529 +Thailand,2007,65068149,Asia,70.616,7458.396327 +Togo,1952,1219113,Africa,38.596,859.8086567 +Togo,1957,1357445,Africa,41.208,925.9083202 +Togo,1962,1528098,Africa,43.922,1067.53481 +Togo,1967,1735550,Africa,46.769,1477.59676 +Togo,1972,2056351,Africa,49.759,1649.660188 +Togo,1977,2308582,Africa,52.887,1532.776998 +Togo,1982,2644765,Africa,55.471,1344.577953 +Togo,1987,3154264,Africa,56.941,1202.201361 +Togo,1992,3747553,Africa,58.061,1034.298904 +Togo,1997,4320890,Africa,58.39,982.2869243 +Togo,2002,4977378,Africa,57.561,886.2205765 +Togo,2007,5701579,Africa,58.42,882.9699438 +Trinidad and Tobago,1952,662850,Americas,59.1,3023.271928 +Trinidad and Tobago,1957,764900,Americas,61.8,4100.3934 +Trinidad and Tobago,1962,887498,Americas,64.9,4997.523971 +Trinidad and Tobago,1967,960155,Americas,65.4,5621.368472 +Trinidad and Tobago,1972,975199,Americas,65.9,6619.551419 +Trinidad and Tobago,1977,1039009,Americas,68.3,7899.554209 +Trinidad and Tobago,1982,1116479,Americas,68.832,9119.528607 +Trinidad and Tobago,1987,1191336,Americas,69.582,7388.597823 +Trinidad and Tobago,1992,1183669,Americas,69.862,7370.990932 +Trinidad and Tobago,1997,1138101,Americas,69.465,8792.573126 +Trinidad and Tobago,2002,1101832,Americas,68.976,11460.60023 +Trinidad and Tobago,2007,1056608,Americas,69.819,18008.50924 +Tunisia,1952,3647735,Africa,44.6,1468.475631 +Tunisia,1957,3950849,Africa,47.1,1395.232468 +Tunisia,1962,4286552,Africa,49.579,1660.30321 +Tunisia,1967,4786986,Africa,52.053,1932.360167 +Tunisia,1972,5303507,Africa,55.602,2753.285994 +Tunisia,1977,6005061,Africa,59.837,3120.876811 +Tunisia,1982,6734098,Africa,64.048,3560.233174 +Tunisia,1987,7724976,Africa,66.894,3810.419296 +Tunisia,1992,8523077,Africa,70.001,4332.720164 +Tunisia,1997,9231669,Africa,71.973,4876.798614 +Tunisia,2002,9770575,Africa,73.042,5722.895655 +Tunisia,2007,10276158,Africa,73.923,7092.923025 +Turkey,1952,22235677,Europe,43.585,1969.10098 +Turkey,1957,25670939,Europe,48.079,2218.754257 +Turkey,1962,29788695,Europe,52.098,2322.869908 +Turkey,1967,33411317,Europe,54.336,2826.356387 +Turkey,1972,37492953,Europe,57.005,3450.69638 +Turkey,1977,42404033,Europe,59.507,4269.122326 +Turkey,1982,47328791,Europe,61.036,4241.356344 +Turkey,1987,52881328,Europe,63.108,5089.043686 +Turkey,1992,58179144,Europe,66.146,5678.348271 +Turkey,1997,63047647,Europe,68.835,6601.429915 +Turkey,2002,67308928,Europe,70.845,6508.085718 +Turkey,2007,71158647,Europe,71.777,8458.276384 +Uganda,1952,5824797,Africa,39.978,734.753484 +Uganda,1957,6675501,Africa,42.571,774.3710692 +Uganda,1962,7688797,Africa,45.344,767.2717398 +Uganda,1967,8900294,Africa,48.051,908.9185217 +Uganda,1972,10190285,Africa,51.016,950.735869 +Uganda,1977,11457758,Africa,50.35,843.7331372 +Uganda,1982,12939400,Africa,49.849,682.2662268 +Uganda,1987,15283050,Africa,51.509,617.7244065 +Uganda,1992,18252190,Africa,48.825,644.1707969 +Uganda,1997,21210254,Africa,44.578,816.559081 +Uganda,2002,24739869,Africa,47.813,927.7210018 +Uganda,2007,29170398,Africa,51.542,1056.380121 +United Kingdom,1952,50430000,Europe,69.18,9979.508487 +United Kingdom,1957,51430000,Europe,70.42,11283.17795 +United Kingdom,1962,53292000,Europe,70.76,12477.17707 +United Kingdom,1967,54959000,Europe,71.36,14142.85089 +United Kingdom,1972,56079000,Europe,72.01,15895.11641 +United Kingdom,1977,56179000,Europe,72.76,17428.74846 +United Kingdom,1982,56339704,Europe,74.04,18232.42452 +United Kingdom,1987,56981620,Europe,75.007,21664.78767 +United Kingdom,1992,57866349,Europe,76.42,22705.09254 +United Kingdom,1997,58808266,Europe,77.218,26074.53136 +United Kingdom,2002,59912431,Europe,78.471,29478.99919 +United Kingdom,2007,60776238,Europe,79.425,33203.26128 +United States,1952,157553000,Americas,68.44,13990.48208 +United States,1957,171984000,Americas,69.49,14847.12712 +United States,1962,186538000,Americas,70.21,16173.14586 +United States,1967,198712000,Americas,70.76,19530.36557 +United States,1972,209896000,Americas,71.34,21806.03594 +United States,1977,220239000,Americas,73.38,24072.63213 +United States,1982,232187835,Americas,74.65,25009.55914 +United States,1987,242803533,Americas,75.02,29884.35041 +United States,1992,256894189,Americas,76.09,32003.93224 +United States,1997,272911760,Americas,76.81,35767.43303 +United States,2002,287675526,Americas,77.31,39097.09955 +United States,2007,301139947,Americas,78.242,42951.65309 +Uruguay,1952,2252965,Americas,66.071,5716.766744 +Uruguay,1957,2424959,Americas,67.044,6150.772969 +Uruguay,1962,2598466,Americas,68.253,5603.357717 +Uruguay,1967,2748579,Americas,68.468,5444.61962 +Uruguay,1972,2829526,Americas,68.673,5703.408898 +Uruguay,1977,2873520,Americas,69.481,6504.339663 +Uruguay,1982,2953997,Americas,70.805,6920.223051 +Uruguay,1987,3045153,Americas,71.918,7452.398969 +Uruguay,1992,3149262,Americas,72.752,8137.004775 +Uruguay,1997,3262838,Americas,74.223,9230.240708 +Uruguay,2002,3363085,Americas,75.307,7727.002004 +Uruguay,2007,3447496,Americas,76.384,10611.46299 +Venezuela,1952,5439568,Americas,55.088,7689.799761 +Venezuela,1957,6702668,Americas,57.907,9802.466526 +Venezuela,1962,8143375,Americas,60.77,8422.974165 +Venezuela,1967,9709552,Americas,63.479,9541.474188 +Venezuela,1972,11515649,Americas,65.712,10505.25966 +Venezuela,1977,13503563,Americas,67.456,13143.95095 +Venezuela,1982,15620766,Americas,68.557,11152.41011 +Venezuela,1987,17910182,Americas,70.19,9883.584648 +Venezuela,1992,20265563,Americas,71.15,10733.92631 +Venezuela,1997,22374398,Americas,72.146,10165.49518 +Venezuela,2002,24287670,Americas,72.766,8605.047831 +Venezuela,2007,26084662,Americas,73.747,11415.80569 +Vietnam,1952,26246839,Asia,40.412,605.0664917 +Vietnam,1957,28998543,Asia,42.887,676.2854478 +Vietnam,1962,33796140,Asia,45.363,772.0491602 +Vietnam,1967,39463910,Asia,47.838,637.1232887 +Vietnam,1972,44655014,Asia,50.254,699.5016441 +Vietnam,1977,50533506,Asia,55.764,713.5371196 +Vietnam,1982,56142181,Asia,58.816,707.2357863 +Vietnam,1987,62826491,Asia,62.82,820.7994449 +Vietnam,1992,69940728,Asia,67.662,989.0231487 +Vietnam,1997,76048996,Asia,70.672,1385.896769 +Vietnam,2002,80908147,Asia,73.017,1764.456677 +Vietnam,2007,85262356,Asia,74.249,2441.576404 +West Bank and Gaza,1952,1030585,Asia,43.16,1515.592329 +West Bank and Gaza,1957,1070439,Asia,45.671,1827.067742 +West Bank and Gaza,1962,1133134,Asia,48.127,2198.956312 +West Bank and Gaza,1967,1142636,Asia,51.631,2649.715007 +West Bank and Gaza,1972,1089572,Asia,56.532,3133.409277 +West Bank and Gaza,1977,1261091,Asia,60.765,3682.831494 +West Bank and Gaza,1982,1425876,Asia,64.406,4336.032082 +West Bank and Gaza,1987,1691210,Asia,67.046,5107.197384 +West Bank and Gaza,1992,2104779,Asia,69.718,6017.654756 +West Bank and Gaza,1997,2826046,Asia,71.096,7110.667619 +West Bank and Gaza,2002,3389578,Asia,72.37,4515.487575 +West Bank and Gaza,2007,4018332,Asia,73.422,3025.349798 +Yemen Rep.,1952,4963829,Asia,32.548,781.7175761 +Yemen Rep.,1957,5498090,Asia,33.97,804.8304547 +Yemen Rep.,1962,6120081,Asia,35.18,825.6232006 +Yemen Rep.,1967,6740785,Asia,36.984,862.4421463 +Yemen Rep.,1972,7407075,Asia,39.848,1265.047031 +Yemen Rep.,1977,8403990,Asia,44.175,1829.765177 +Yemen Rep.,1982,9657618,Asia,49.113,1977.55701 +Yemen Rep.,1987,11219340,Asia,52.922,1971.741538 +Yemen Rep.,1992,13367997,Asia,55.599,1879.496673 +Yemen Rep.,1997,15826497,Asia,58.02,2117.484526 +Yemen Rep.,2002,18701257,Asia,60.308,2234.820827 +Yemen Rep.,2007,22211743,Asia,62.698,2280.769906 +Zambia,1952,2672000,Africa,42.038,1147.388831 +Zambia,1957,3016000,Africa,44.077,1311.956766 +Zambia,1962,3421000,Africa,46.023,1452.725766 +Zambia,1967,3900000,Africa,47.768,1777.077318 +Zambia,1972,4506497,Africa,50.107,1773.498265 +Zambia,1977,5216550,Africa,51.386,1588.688299 +Zambia,1982,6100407,Africa,51.821,1408.678565 +Zambia,1987,7272406,Africa,50.821,1213.315116 +Zambia,1992,8381163,Africa,46.1,1210.884633 +Zambia,1997,9417789,Africa,40.238,1071.353818 +Zambia,2002,10595811,Africa,39.193,1071.613938 +Zambia,2007,11746035,Africa,42.384,1271.211593 +Zimbabwe,1952,3080907,Africa,48.451,406.8841148 +Zimbabwe,1957,3646340,Africa,50.469,518.7642681 +Zimbabwe,1962,4277736,Africa,52.358,527.2721818 +Zimbabwe,1967,4995432,Africa,53.995,569.7950712 +Zimbabwe,1972,5861135,Africa,55.635,799.3621758 +Zimbabwe,1977,6642107,Africa,57.674,685.5876821 +Zimbabwe,1982,7636524,Africa,60.363,788.8550411 +Zimbabwe,1987,9216418,Africa,62.351,706.1573059 +Zimbabwe,1992,10704340,Africa,60.377,693.4207856 +Zimbabwe,1997,11404948,Africa,46.809,792.4499603 +Zimbabwe,2002,11926563,Africa,39.989,672.0386227 +Zimbabwe,2007,12311143,Africa,43.487,469.7092981 diff --git a/data/gapminder_data.csv b/data/gapminder_data.csv new file mode 100644 index 000000000..661ddefc6 --- /dev/null +++ b/data/gapminder_data.csv @@ -0,0 +1,1705 @@ +country,year,pop,continent,lifeExp,gdpPercap +Afghanistan,1952,8425333,Asia,28.801,779.4453145 +Afghanistan,1957,9240934,Asia,30.332,820.8530296 +Afghanistan,1962,10267083,Asia,31.997,853.10071 +Afghanistan,1967,11537966,Asia,34.02,836.1971382 +Afghanistan,1972,13079460,Asia,36.088,739.9811058 +Afghanistan,1977,14880372,Asia,38.438,786.11336 +Afghanistan,1982,12881816,Asia,39.854,978.0114388 +Afghanistan,1987,13867957,Asia,40.822,852.3959448 +Afghanistan,1992,16317921,Asia,41.674,649.3413952 +Afghanistan,1997,22227415,Asia,41.763,635.341351 +Afghanistan,2002,25268405,Asia,42.129,726.7340548 +Afghanistan,2007,31889923,Asia,43.828,974.5803384 +Albania,1952,1282697,Europe,55.23,1601.056136 +Albania,1957,1476505,Europe,59.28,1942.284244 +Albania,1962,1728137,Europe,64.82,2312.888958 +Albania,1967,1984060,Europe,66.22,2760.196931 +Albania,1972,2263554,Europe,67.69,3313.422188 +Albania,1977,2509048,Europe,68.93,3533.00391 +Albania,1982,2780097,Europe,70.42,3630.880722 +Albania,1987,3075321,Europe,72,3738.932735 +Albania,1992,3326498,Europe,71.581,2497.437901 +Albania,1997,3428038,Europe,72.95,3193.054604 +Albania,2002,3508512,Europe,75.651,4604.211737 +Albania,2007,3600523,Europe,76.423,5937.029526 +Algeria,1952,9279525,Africa,43.077,2449.008185 +Algeria,1957,10270856,Africa,45.685,3013.976023 +Algeria,1962,11000948,Africa,48.303,2550.81688 +Algeria,1967,12760499,Africa,51.407,3246.991771 +Algeria,1972,14760787,Africa,54.518,4182.663766 +Algeria,1977,17152804,Africa,58.014,4910.416756 +Algeria,1982,20033753,Africa,61.368,5745.160213 +Algeria,1987,23254956,Africa,65.799,5681.358539 +Algeria,1992,26298373,Africa,67.744,5023.216647 +Algeria,1997,29072015,Africa,69.152,4797.295051 +Algeria,2002,31287142,Africa,70.994,5288.040382 +Algeria,2007,33333216,Africa,72.301,6223.367465 +Angola,1952,4232095,Africa,30.015,3520.610273 +Angola,1957,4561361,Africa,31.999,3827.940465 +Angola,1962,4826015,Africa,34,4269.276742 +Angola,1967,5247469,Africa,35.985,5522.776375 +Angola,1972,5894858,Africa,37.928,5473.288005 +Angola,1977,6162675,Africa,39.483,3008.647355 +Angola,1982,7016384,Africa,39.942,2756.953672 +Angola,1987,7874230,Africa,39.906,2430.208311 +Angola,1992,8735988,Africa,40.647,2627.845685 +Angola,1997,9875024,Africa,40.963,2277.140884 +Angola,2002,10866106,Africa,41.003,2773.287312 +Angola,2007,12420476,Africa,42.731,4797.231267 +Argentina,1952,17876956,Americas,62.485,5911.315053 +Argentina,1957,19610538,Americas,64.399,6856.856212 +Argentina,1962,21283783,Americas,65.142,7133.166023 +Argentina,1967,22934225,Americas,65.634,8052.953021 +Argentina,1972,24779799,Americas,67.065,9443.038526 +Argentina,1977,26983828,Americas,68.481,10079.02674 +Argentina,1982,29341374,Americas,69.942,8997.897412 +Argentina,1987,31620918,Americas,70.774,9139.671389 +Argentina,1992,33958947,Americas,71.868,9308.41871 +Argentina,1997,36203463,Americas,73.275,10967.28195 +Argentina,2002,38331121,Americas,74.34,8797.640716 +Argentina,2007,40301927,Americas,75.32,12779.37964 +Australia,1952,8691212,Oceania,69.12,10039.59564 +Australia,1957,9712569,Oceania,70.33,10949.64959 +Australia,1962,10794968,Oceania,70.93,12217.22686 +Australia,1967,11872264,Oceania,71.1,14526.12465 +Australia,1972,13177000,Oceania,71.93,16788.62948 +Australia,1977,14074100,Oceania,73.49,18334.19751 +Australia,1982,15184200,Oceania,74.74,19477.00928 +Australia,1987,16257249,Oceania,76.32,21888.88903 +Australia,1992,17481977,Oceania,77.56,23424.76683 +Australia,1997,18565243,Oceania,78.83,26997.93657 +Australia,2002,19546792,Oceania,80.37,30687.75473 +Australia,2007,20434176,Oceania,81.235,34435.36744 +Austria,1952,6927772,Europe,66.8,6137.076492 +Austria,1957,6965860,Europe,67.48,8842.59803 +Austria,1962,7129864,Europe,69.54,10750.72111 +Austria,1967,7376998,Europe,70.14,12834.6024 +Austria,1972,7544201,Europe,70.63,16661.6256 +Austria,1977,7568430,Europe,72.17,19749.4223 +Austria,1982,7574613,Europe,73.18,21597.08362 +Austria,1987,7578903,Europe,74.94,23687.82607 +Austria,1992,7914969,Europe,76.04,27042.01868 +Austria,1997,8069876,Europe,77.51,29095.92066 +Austria,2002,8148312,Europe,78.98,32417.60769 +Austria,2007,8199783,Europe,79.829,36126.4927 +Bahrain,1952,120447,Asia,50.939,9867.084765 +Bahrain,1957,138655,Asia,53.832,11635.79945 +Bahrain,1962,171863,Asia,56.923,12753.27514 +Bahrain,1967,202182,Asia,59.923,14804.6727 +Bahrain,1972,230800,Asia,63.3,18268.65839 +Bahrain,1977,297410,Asia,65.593,19340.10196 +Bahrain,1982,377967,Asia,69.052,19211.14731 +Bahrain,1987,454612,Asia,70.75,18524.02406 +Bahrain,1992,529491,Asia,72.601,19035.57917 +Bahrain,1997,598561,Asia,73.925,20292.01679 +Bahrain,2002,656397,Asia,74.795,23403.55927 +Bahrain,2007,708573,Asia,75.635,29796.04834 +Bangladesh,1952,46886859,Asia,37.484,684.2441716 +Bangladesh,1957,51365468,Asia,39.348,661.6374577 +Bangladesh,1962,56839289,Asia,41.216,686.3415538 +Bangladesh,1967,62821884,Asia,43.453,721.1860862 +Bangladesh,1972,70759295,Asia,45.252,630.2336265 +Bangladesh,1977,80428306,Asia,46.923,659.8772322 +Bangladesh,1982,93074406,Asia,50.009,676.9818656 +Bangladesh,1987,103764241,Asia,52.819,751.9794035 +Bangladesh,1992,113704579,Asia,56.018,837.8101643 +Bangladesh,1997,123315288,Asia,59.412,972.7700352 +Bangladesh,2002,135656790,Asia,62.013,1136.39043 +Bangladesh,2007,150448339,Asia,64.062,1391.253792 +Belgium,1952,8730405,Europe,68,8343.105127 +Belgium,1957,8989111,Europe,69.24,9714.960623 +Belgium,1962,9218400,Europe,70.25,10991.20676 +Belgium,1967,9556500,Europe,70.94,13149.04119 +Belgium,1972,9709100,Europe,71.44,16672.14356 +Belgium,1977,9821800,Europe,72.8,19117.97448 +Belgium,1982,9856303,Europe,73.93,20979.84589 +Belgium,1987,9870200,Europe,75.35,22525.56308 +Belgium,1992,10045622,Europe,76.46,25575.57069 +Belgium,1997,10199787,Europe,77.53,27561.19663 +Belgium,2002,10311970,Europe,78.32,30485.88375 +Belgium,2007,10392226,Europe,79.441,33692.60508 +Benin,1952,1738315,Africa,38.223,1062.7522 +Benin,1957,1925173,Africa,40.358,959.6010805 +Benin,1962,2151895,Africa,42.618,949.4990641 +Benin,1967,2427334,Africa,44.885,1035.831411 +Benin,1972,2761407,Africa,47.014,1085.796879 +Benin,1977,3168267,Africa,49.19,1029.161251 +Benin,1982,3641603,Africa,50.904,1277.897616 +Benin,1987,4243788,Africa,52.337,1225.85601 +Benin,1992,4981671,Africa,53.919,1191.207681 +Benin,1997,6066080,Africa,54.777,1232.975292 +Benin,2002,7026113,Africa,54.406,1372.877931 +Benin,2007,8078314,Africa,56.728,1441.284873 +Bolivia,1952,2883315,Americas,40.414,2677.326347 +Bolivia,1957,3211738,Americas,41.89,2127.686326 +Bolivia,1962,3593918,Americas,43.428,2180.972546 +Bolivia,1967,4040665,Americas,45.032,2586.886053 +Bolivia,1972,4565872,Americas,46.714,2980.331339 +Bolivia,1977,5079716,Americas,50.023,3548.097832 +Bolivia,1982,5642224,Americas,53.859,3156.510452 +Bolivia,1987,6156369,Americas,57.251,2753.69149 +Bolivia,1992,6893451,Americas,59.957,2961.699694 +Bolivia,1997,7693188,Americas,62.05,3326.143191 +Bolivia,2002,8445134,Americas,63.883,3413.26269 +Bolivia,2007,9119152,Americas,65.554,3822.137084 +Bosnia and Herzegovina,1952,2791000,Europe,53.82,973.5331948 +Bosnia and Herzegovina,1957,3076000,Europe,58.45,1353.989176 +Bosnia and Herzegovina,1962,3349000,Europe,61.93,1709.683679 +Bosnia and Herzegovina,1967,3585000,Europe,64.79,2172.352423 +Bosnia and Herzegovina,1972,3819000,Europe,67.45,2860.16975 +Bosnia and Herzegovina,1977,4086000,Europe,69.86,3528.481305 +Bosnia and Herzegovina,1982,4172693,Europe,70.69,4126.613157 +Bosnia and Herzegovina,1987,4338977,Europe,71.14,4314.114757 +Bosnia and Herzegovina,1992,4256013,Europe,72.178,2546.781445 +Bosnia and Herzegovina,1997,3607000,Europe,73.244,4766.355904 +Bosnia and Herzegovina,2002,4165416,Europe,74.09,6018.975239 +Bosnia and Herzegovina,2007,4552198,Europe,74.852,7446.298803 +Botswana,1952,442308,Africa,47.622,851.2411407 +Botswana,1957,474639,Africa,49.618,918.2325349 +Botswana,1962,512764,Africa,51.52,983.6539764 +Botswana,1967,553541,Africa,53.298,1214.709294 +Botswana,1972,619351,Africa,56.024,2263.611114 +Botswana,1977,781472,Africa,59.319,3214.857818 +Botswana,1982,970347,Africa,61.484,4551.14215 +Botswana,1987,1151184,Africa,63.622,6205.88385 +Botswana,1992,1342614,Africa,62.745,7954.111645 +Botswana,1997,1536536,Africa,52.556,8647.142313 +Botswana,2002,1630347,Africa,46.634,11003.60508 +Botswana,2007,1639131,Africa,50.728,12569.85177 +Brazil,1952,56602560,Americas,50.917,2108.944355 +Brazil,1957,65551171,Americas,53.285,2487.365989 +Brazil,1962,76039390,Americas,55.665,3336.585802 +Brazil,1967,88049823,Americas,57.632,3429.864357 +Brazil,1972,100840058,Americas,59.504,4985.711467 +Brazil,1977,114313951,Americas,61.489,6660.118654 +Brazil,1982,128962939,Americas,63.336,7030.835878 +Brazil,1987,142938076,Americas,65.205,7807.095818 +Brazil,1992,155975974,Americas,67.057,6950.283021 +Brazil,1997,168546719,Americas,69.388,7957.980824 +Brazil,2002,179914212,Americas,71.006,8131.212843 +Brazil,2007,190010647,Americas,72.39,9065.800825 +Bulgaria,1952,7274900,Europe,59.6,2444.286648 +Bulgaria,1957,7651254,Europe,66.61,3008.670727 +Bulgaria,1962,8012946,Europe,69.51,4254.337839 +Bulgaria,1967,8310226,Europe,70.42,5577.0028 +Bulgaria,1972,8576200,Europe,70.9,6597.494398 +Bulgaria,1977,8797022,Europe,70.81,7612.240438 +Bulgaria,1982,8892098,Europe,71.08,8224.191647 +Bulgaria,1987,8971958,Europe,71.34,8239.854824 +Bulgaria,1992,8658506,Europe,71.19,6302.623438 +Bulgaria,1997,8066057,Europe,70.32,5970.38876 +Bulgaria,2002,7661799,Europe,72.14,7696.777725 +Bulgaria,2007,7322858,Europe,73.005,10680.79282 +Burkina Faso,1952,4469979,Africa,31.975,543.2552413 +Burkina Faso,1957,4713416,Africa,34.906,617.1834648 +Burkina Faso,1962,4919632,Africa,37.814,722.5120206 +Burkina Faso,1967,5127935,Africa,40.697,794.8265597 +Burkina Faso,1972,5433886,Africa,43.591,854.7359763 +Burkina Faso,1977,5889574,Africa,46.137,743.3870368 +Burkina Faso,1982,6634596,Africa,48.122,807.1985855 +Burkina Faso,1987,7586551,Africa,49.557,912.0631417 +Burkina Faso,1992,8878303,Africa,50.26,931.7527731 +Burkina Faso,1997,10352843,Africa,50.324,946.2949618 +Burkina Faso,2002,12251209,Africa,50.65,1037.645221 +Burkina Faso,2007,14326203,Africa,52.295,1217.032994 +Burundi,1952,2445618,Africa,39.031,339.2964587 +Burundi,1957,2667518,Africa,40.533,379.5646281 +Burundi,1962,2961915,Africa,42.045,355.2032273 +Burundi,1967,3330989,Africa,43.548,412.9775136 +Burundi,1972,3529983,Africa,44.057,464.0995039 +Burundi,1977,3834415,Africa,45.91,556.1032651 +Burundi,1982,4580410,Africa,47.471,559.603231 +Burundi,1987,5126023,Africa,48.211,621.8188189 +Burundi,1992,5809236,Africa,44.736,631.6998778 +Burundi,1997,6121610,Africa,45.326,463.1151478 +Burundi,2002,7021078,Africa,47.36,446.4035126 +Burundi,2007,8390505,Africa,49.58,430.0706916 +Cambodia,1952,4693836,Asia,39.417,368.4692856 +Cambodia,1957,5322536,Asia,41.366,434.0383364 +Cambodia,1962,6083619,Asia,43.415,496.9136476 +Cambodia,1967,6960067,Asia,45.415,523.4323142 +Cambodia,1972,7450606,Asia,40.317,421.6240257 +Cambodia,1977,6978607,Asia,31.22,524.9721832 +Cambodia,1982,7272485,Asia,50.957,624.4754784 +Cambodia,1987,8371791,Asia,53.914,683.8955732 +Cambodia,1992,10150094,Asia,55.803,682.3031755 +Cambodia,1997,11782962,Asia,56.534,734.28517 +Cambodia,2002,12926707,Asia,56.752,896.2260153 +Cambodia,2007,14131858,Asia,59.723,1713.778686 +Cameroon,1952,5009067,Africa,38.523,1172.667655 +Cameroon,1957,5359923,Africa,40.428,1313.048099 +Cameroon,1962,5793633,Africa,42.643,1399.607441 +Cameroon,1967,6335506,Africa,44.799,1508.453148 +Cameroon,1972,7021028,Africa,47.049,1684.146528 +Cameroon,1977,7959865,Africa,49.355,1783.432873 +Cameroon,1982,9250831,Africa,52.961,2367.983282 +Cameroon,1987,10780667,Africa,54.985,2602.664206 +Cameroon,1992,12467171,Africa,54.314,1793.163278 +Cameroon,1997,14195809,Africa,52.199,1694.337469 +Cameroon,2002,15929988,Africa,49.856,1934.011449 +Cameroon,2007,17696293,Africa,50.43,2042.09524 +Canada,1952,14785584,Americas,68.75,11367.16112 +Canada,1957,17010154,Americas,69.96,12489.95006 +Canada,1962,18985849,Americas,71.3,13462.48555 +Canada,1967,20819767,Americas,72.13,16076.58803 +Canada,1972,22284500,Americas,72.88,18970.57086 +Canada,1977,23796400,Americas,74.21,22090.88306 +Canada,1982,25201900,Americas,75.76,22898.79214 +Canada,1987,26549700,Americas,76.86,26626.51503 +Canada,1992,28523502,Americas,77.95,26342.88426 +Canada,1997,30305843,Americas,78.61,28954.92589 +Canada,2002,31902268,Americas,79.77,33328.96507 +Canada,2007,33390141,Americas,80.653,36319.23501 +Central African Republic,1952,1291695,Africa,35.463,1071.310713 +Central African Republic,1957,1392284,Africa,37.464,1190.844328 +Central African Republic,1962,1523478,Africa,39.475,1193.068753 +Central African Republic,1967,1733638,Africa,41.478,1136.056615 +Central African Republic,1972,1927260,Africa,43.457,1070.013275 +Central African Republic,1977,2167533,Africa,46.775,1109.374338 +Central African Republic,1982,2476971,Africa,48.295,956.7529907 +Central African Republic,1987,2840009,Africa,50.485,844.8763504 +Central African Republic,1992,3265124,Africa,49.396,747.9055252 +Central African Republic,1997,3696513,Africa,46.066,740.5063317 +Central African Republic,2002,4048013,Africa,43.308,738.6906068 +Central African Republic,2007,4369038,Africa,44.741,706.016537 +Chad,1952,2682462,Africa,38.092,1178.665927 +Chad,1957,2894855,Africa,39.881,1308.495577 +Chad,1962,3150417,Africa,41.716,1389.817618 +Chad,1967,3495967,Africa,43.601,1196.810565 +Chad,1972,3899068,Africa,45.569,1104.103987 +Chad,1977,4388260,Africa,47.383,1133.98495 +Chad,1982,4875118,Africa,49.517,797.9081006 +Chad,1987,5498955,Africa,51.051,952.386129 +Chad,1992,6429417,Africa,51.724,1058.0643 +Chad,1997,7562011,Africa,51.573,1004.961353 +Chad,2002,8835739,Africa,50.525,1156.18186 +Chad,2007,10238807,Africa,50.651,1704.063724 +Chile,1952,6377619,Americas,54.745,3939.978789 +Chile,1957,7048426,Americas,56.074,4315.622723 +Chile,1962,7961258,Americas,57.924,4519.094331 +Chile,1967,8858908,Americas,60.523,5106.654313 +Chile,1972,9717524,Americas,63.441,5494.024437 +Chile,1977,10599793,Americas,67.052,4756.763836 +Chile,1982,11487112,Americas,70.565,5095.665738 +Chile,1987,12463354,Americas,72.492,5547.063754 +Chile,1992,13572994,Americas,74.126,7596.125964 +Chile,1997,14599929,Americas,75.816,10118.05318 +Chile,2002,15497046,Americas,77.86,10778.78385 +Chile,2007,16284741,Americas,78.553,13171.63885 +China,1952,556263527.999989,Asia,44,400.448610699994 +China,1957,637408000,Asia,50.54896,575.9870009 +China,1962,665770000,Asia,44.50136,487.6740183 +China,1967,754550000,Asia,58.38112,612.7056934 +China,1972,862030000,Asia,63.11888,676.9000921 +China,1977,943455000,Asia,63.96736,741.2374699 +China,1982,1000281000,Asia,65.525,962.4213805 +China,1987,1084035000,Asia,67.274,1378.904018 +China,1992,1164970000,Asia,68.69,1655.784158 +China,1997,1230075000,Asia,70.426,2289.234136 +China,2002,1280400000,Asia,72.028,3119.280896 +China,2007,1318683096,Asia,72.961,4959.114854 +Colombia,1952,12350771,Americas,50.643,2144.115096 +Colombia,1957,14485993,Americas,55.118,2323.805581 +Colombia,1962,17009885,Americas,57.863,2492.351109 +Colombia,1967,19764027,Americas,59.963,2678.729839 +Colombia,1972,22542890,Americas,61.623,3264.660041 +Colombia,1977,25094412,Americas,63.837,3815.80787 +Colombia,1982,27764644,Americas,66.653,4397.575659 +Colombia,1987,30964245,Americas,67.768,4903.2191 +Colombia,1992,34202721,Americas,68.421,5444.648617 +Colombia,1997,37657830,Americas,70.313,6117.361746 +Colombia,2002,41008227,Americas,71.682,5755.259962 +Colombia,2007,44227550,Americas,72.889,7006.580419 +Comoros,1952,153936,Africa,40.715,1102.990936 +Comoros,1957,170928,Africa,42.46,1211.148548 +Comoros,1962,191689,Africa,44.467,1406.648278 +Comoros,1967,217378,Africa,46.472,1876.029643 +Comoros,1972,250027,Africa,48.944,1937.577675 +Comoros,1977,304739,Africa,50.939,1172.603047 +Comoros,1982,348643,Africa,52.933,1267.100083 +Comoros,1987,395114,Africa,54.926,1315.980812 +Comoros,1992,454429,Africa,57.939,1246.90737 +Comoros,1997,527982,Africa,60.66,1173.618235 +Comoros,2002,614382,Africa,62.974,1075.811558 +Comoros,2007,710960,Africa,65.152,986.1478792 +Congo Dem. Rep.,1952,14100005,Africa,39.143,780.5423257 +Congo Dem. Rep.,1957,15577932,Africa,40.652,905.8602303 +Congo Dem. Rep.,1962,17486434,Africa,42.122,896.3146335 +Congo Dem. Rep.,1967,19941073,Africa,44.056,861.5932424 +Congo Dem. Rep.,1972,23007669,Africa,45.989,904.8960685 +Congo Dem. Rep.,1977,26480870,Africa,47.804,795.757282 +Congo Dem. Rep.,1982,30646495,Africa,47.784,673.7478181 +Congo Dem. Rep.,1987,35481645,Africa,47.412,672.774812 +Congo Dem. Rep.,1992,41672143,Africa,45.548,457.7191807 +Congo Dem. Rep.,1997,47798986,Africa,42.587,312.188423 +Congo Dem. Rep.,2002,55379852,Africa,44.966,241.1658765 +Congo Dem. Rep.,2007,64606759,Africa,46.462,277.5518587 +Congo Rep.,1952,854885,Africa,42.111,2125.621418 +Congo Rep.,1957,940458,Africa,45.053,2315.056572 +Congo Rep.,1962,1047924,Africa,48.435,2464.783157 +Congo Rep.,1967,1179760,Africa,52.04,2677.939642 +Congo Rep.,1972,1340458,Africa,54.907,3213.152683 +Congo Rep.,1977,1536769,Africa,55.625,3259.178978 +Congo Rep.,1982,1774735,Africa,56.695,4879.507522 +Congo Rep.,1987,2064095,Africa,57.47,4201.194937 +Congo Rep.,1992,2409073,Africa,56.433,4016.239529 +Congo Rep.,1997,2800947,Africa,52.962,3484.164376 +Congo Rep.,2002,3328795,Africa,52.97,3484.06197 +Congo Rep.,2007,3800610,Africa,55.322,3632.557798 +Costa Rica,1952,926317,Americas,57.206,2627.009471 +Costa Rica,1957,1112300,Americas,60.026,2990.010802 +Costa Rica,1962,1345187,Americas,62.842,3460.937025 +Costa Rica,1967,1588717,Americas,65.424,4161.727834 +Costa Rica,1972,1834796,Americas,67.849,5118.146939 +Costa Rica,1977,2108457,Americas,70.75,5926.876967 +Costa Rica,1982,2424367,Americas,73.45,5262.734751 +Costa Rica,1987,2799811,Americas,74.752,5629.915318 +Costa Rica,1992,3173216,Americas,75.713,6160.416317 +Costa Rica,1997,3518107,Americas,77.26,6677.045314 +Costa Rica,2002,3834934,Americas,78.123,7723.447195 +Costa Rica,2007,4133884,Americas,78.782,9645.06142 +"Cote d'Ivoire",1952,2977019,Africa,40.477,1388.594732 +"Cote d'Ivoire",1957,3300000,Africa,42.469,1500.895925 +"Cote d'Ivoire",1962,3832408,Africa,44.93,1728.869428 +"Cote d'Ivoire",1967,4744870,Africa,47.35,2052.050473 +"Cote d'Ivoire",1972,6071696,Africa,49.801,2378.201111 +"Cote d'Ivoire",1977,7459574,Africa,52.374,2517.736547 +"Cote d'Ivoire",1982,9025951,Africa,53.983,2602.710169 +"Cote d'Ivoire",1987,10761098,Africa,54.655,2156.956069 +"Cote d'Ivoire",1992,12772596,Africa,52.044,1648.073791 +"Cote d'Ivoire",1997,14625967,Africa,47.991,1786.265407 +"Cote d'Ivoire",2002,16252726,Africa,46.832,1648.800823 +"Cote d'Ivoire",2007,18013409,Africa,48.328,1544.750112 +Croatia,1952,3882229,Europe,61.21,3119.23652 +Croatia,1957,3991242,Europe,64.77,4338.231617 +Croatia,1962,4076557,Europe,67.13,5477.890018 +Croatia,1967,4174366,Europe,68.5,6960.297861 +Croatia,1972,4225310,Europe,69.61,9164.090127 +Croatia,1977,4318673,Europe,70.64,11305.38517 +Croatia,1982,4413368,Europe,70.46,13221.82184 +Croatia,1987,4484310,Europe,71.52,13822.58394 +Croatia,1992,4494013,Europe,72.527,8447.794873 +Croatia,1997,4444595,Europe,73.68,9875.604515 +Croatia,2002,4481020,Europe,74.876,11628.38895 +Croatia,2007,4493312,Europe,75.748,14619.22272 +Cuba,1952,6007797,Americas,59.421,5586.53878 +Cuba,1957,6640752,Americas,62.325,6092.174359 +Cuba,1962,7254373,Americas,65.246,5180.75591 +Cuba,1967,8139332,Americas,68.29,5690.268015 +Cuba,1972,8831348,Americas,70.723,5305.445256 +Cuba,1977,9537988,Americas,72.649,6380.494966 +Cuba,1982,9789224,Americas,73.717,7316.918107 +Cuba,1987,10239839,Americas,74.174,7532.924763 +Cuba,1992,10723260,Americas,74.414,5592.843963 +Cuba,1997,10983007,Americas,76.151,5431.990415 +Cuba,2002,11226999,Americas,77.158,6340.646683 +Cuba,2007,11416987,Americas,78.273,8948.102923 +Czech Republic,1952,9125183,Europe,66.87,6876.14025 +Czech Republic,1957,9513758,Europe,69.03,8256.343918 +Czech Republic,1962,9620282,Europe,69.9,10136.86713 +Czech Republic,1967,9835109,Europe,70.38,11399.44489 +Czech Republic,1972,9862158,Europe,70.29,13108.4536 +Czech Republic,1977,10161915,Europe,70.71,14800.16062 +Czech Republic,1982,10303704,Europe,70.96,15377.22855 +Czech Republic,1987,10311597,Europe,71.58,16310.4434 +Czech Republic,1992,10315702,Europe,72.4,14297.02122 +Czech Republic,1997,10300707,Europe,74.01,16048.51424 +Czech Republic,2002,10256295,Europe,75.51,17596.21022 +Czech Republic,2007,10228744,Europe,76.486,22833.30851 +Denmark,1952,4334000,Europe,70.78,9692.385245 +Denmark,1957,4487831,Europe,71.81,11099.65935 +Denmark,1962,4646899,Europe,72.35,13583.31351 +Denmark,1967,4838800,Europe,72.96,15937.21123 +Denmark,1972,4991596,Europe,73.47,18866.20721 +Denmark,1977,5088419,Europe,74.69,20422.9015 +Denmark,1982,5117810,Europe,74.63,21688.04048 +Denmark,1987,5127024,Europe,74.8,25116.17581 +Denmark,1992,5171393,Europe,75.33,26406.73985 +Denmark,1997,5283663,Europe,76.11,29804.34567 +Denmark,2002,5374693,Europe,77.18,32166.50006 +Denmark,2007,5468120,Europe,78.332,35278.41874 +Djibouti,1952,63149,Africa,34.812,2669.529475 +Djibouti,1957,71851,Africa,37.328,2864.969076 +Djibouti,1962,89898,Africa,39.693,3020.989263 +Djibouti,1967,127617,Africa,42.074,3020.050513 +Djibouti,1972,178848,Africa,44.366,3694.212352 +Djibouti,1977,228694,Africa,46.519,3081.761022 +Djibouti,1982,305991,Africa,48.812,2879.468067 +Djibouti,1987,311025,Africa,50.04,2880.102568 +Djibouti,1992,384156,Africa,51.604,2377.156192 +Djibouti,1997,417908,Africa,53.157,1895.016984 +Djibouti,2002,447416,Africa,53.373,1908.260867 +Djibouti,2007,496374,Africa,54.791,2082.481567 +Dominican Republic,1952,2491346,Americas,45.928,1397.717137 +Dominican Republic,1957,2923186,Americas,49.828,1544.402995 +Dominican Republic,1962,3453434,Americas,53.459,1662.137359 +Dominican Republic,1967,4049146,Americas,56.751,1653.723003 +Dominican Republic,1972,4671329,Americas,59.631,2189.874499 +Dominican Republic,1977,5302800,Americas,61.788,2681.9889 +Dominican Republic,1982,5968349,Americas,63.727,2861.092386 +Dominican Republic,1987,6655297,Americas,66.046,2899.842175 +Dominican Republic,1992,7351181,Americas,68.457,3044.214214 +Dominican Republic,1997,7992357,Americas,69.957,3614.101285 +Dominican Republic,2002,8650322,Americas,70.847,4563.808154 +Dominican Republic,2007,9319622,Americas,72.235,6025.374752 +Ecuador,1952,3548753,Americas,48.357,3522.110717 +Ecuador,1957,4058385,Americas,51.356,3780.546651 +Ecuador,1962,4681707,Americas,54.64,4086.114078 +Ecuador,1967,5432424,Americas,56.678,4579.074215 +Ecuador,1972,6298651,Americas,58.796,5280.99471 +Ecuador,1977,7278866,Americas,61.31,6679.62326 +Ecuador,1982,8365850,Americas,64.342,7213.791267 +Ecuador,1987,9545158,Americas,67.231,6481.776993 +Ecuador,1992,10748394,Americas,69.613,7103.702595 +Ecuador,1997,11911819,Americas,72.312,7429.455877 +Ecuador,2002,12921234,Americas,74.173,5773.044512 +Ecuador,2007,13755680,Americas,74.994,6873.262326 +Egypt,1952,22223309,Africa,41.893,1418.822445 +Egypt,1957,25009741,Africa,44.444,1458.915272 +Egypt,1962,28173309,Africa,46.992,1693.335853 +Egypt,1967,31681188,Africa,49.293,1814.880728 +Egypt,1972,34807417,Africa,51.137,2024.008147 +Egypt,1977,38783863,Africa,53.319,2785.493582 +Egypt,1982,45681811,Africa,56.006,3503.729636 +Egypt,1987,52799062,Africa,59.797,3885.46071 +Egypt,1992,59402198,Africa,63.674,3794.755195 +Egypt,1997,66134291,Africa,67.217,4173.181797 +Egypt,2002,73312559,Africa,69.806,4754.604414 +Egypt,2007,80264543,Africa,71.338,5581.180998 +El Salvador,1952,2042865,Americas,45.262,3048.3029 +El Salvador,1957,2355805,Americas,48.57,3421.523218 +El Salvador,1962,2747687,Americas,52.307,3776.803627 +El Salvador,1967,3232927,Americas,55.855,4358.595393 +El Salvador,1972,3790903,Americas,58.207,4520.246008 +El Salvador,1977,4282586,Americas,56.696,5138.922374 +El Salvador,1982,4474873,Americas,56.604,4098.344175 +El Salvador,1987,4842194,Americas,63.154,4140.442097 +El Salvador,1992,5274649,Americas,66.798,4444.2317 +El Salvador,1997,5783439,Americas,69.535,5154.825496 +El Salvador,2002,6353681,Americas,70.734,5351.568666 +El Salvador,2007,6939688,Americas,71.878,5728.353514 +Equatorial Guinea,1952,216964,Africa,34.482,375.6431231 +Equatorial Guinea,1957,232922,Africa,35.983,426.0964081 +Equatorial Guinea,1962,249220,Africa,37.485,582.8419714 +Equatorial Guinea,1967,259864,Africa,38.987,915.5960025 +Equatorial Guinea,1972,277603,Africa,40.516,672.4122571 +Equatorial Guinea,1977,192675,Africa,42.024,958.5668124 +Equatorial Guinea,1982,285483,Africa,43.662,927.8253427 +Equatorial Guinea,1987,341244,Africa,45.664,966.8968149 +Equatorial Guinea,1992,387838,Africa,47.545,1132.055034 +Equatorial Guinea,1997,439971,Africa,48.245,2814.480755 +Equatorial Guinea,2002,495627,Africa,49.348,7703.4959 +Equatorial Guinea,2007,551201,Africa,51.579,12154.08975 +Eritrea,1952,1438760,Africa,35.928,328.9405571 +Eritrea,1957,1542611,Africa,38.047,344.1618859 +Eritrea,1962,1666618,Africa,40.158,380.9958433 +Eritrea,1967,1820319,Africa,42.189,468.7949699 +Eritrea,1972,2260187,Africa,44.142,514.3242082 +Eritrea,1977,2512642,Africa,44.535,505.7538077 +Eritrea,1982,2637297,Africa,43.89,524.8758493 +Eritrea,1987,2915959,Africa,46.453,521.1341333 +Eritrea,1992,3668440,Africa,49.991,582.8585102 +Eritrea,1997,4058319,Africa,53.378,913.47079 +Eritrea,2002,4414865,Africa,55.24,765.3500015 +Eritrea,2007,4906585,Africa,58.04,641.3695236 +Ethiopia,1952,20860941,Africa,34.078,362.1462796 +Ethiopia,1957,22815614,Africa,36.667,378.9041632 +Ethiopia,1962,25145372,Africa,40.059,419.4564161 +Ethiopia,1967,27860297,Africa,42.115,516.1186438 +Ethiopia,1972,30770372,Africa,43.515,566.2439442 +Ethiopia,1977,34617799,Africa,44.51,556.8083834 +Ethiopia,1982,38111756,Africa,44.916,577.8607471 +Ethiopia,1987,42999530,Africa,46.684,573.7413142 +Ethiopia,1992,52088559,Africa,48.091,421.3534653 +Ethiopia,1997,59861301,Africa,49.402,515.8894013 +Ethiopia,2002,67946797,Africa,50.725,530.0535319 +Ethiopia,2007,76511887,Africa,52.947,690.8055759 +Finland,1952,4090500,Europe,66.55,6424.519071 +Finland,1957,4324000,Europe,67.49,7545.415386 +Finland,1962,4491443,Europe,68.75,9371.842561 +Finland,1967,4605744,Europe,69.83,10921.63626 +Finland,1972,4639657,Europe,70.87,14358.8759 +Finland,1977,4738902,Europe,72.52,15605.42283 +Finland,1982,4826933,Europe,74.55,18533.15761 +Finland,1987,4931729,Europe,74.83,21141.01223 +Finland,1992,5041039,Europe,75.7,20647.16499 +Finland,1997,5134406,Europe,77.13,23723.9502 +Finland,2002,5193039,Europe,78.37,28204.59057 +Finland,2007,5238460,Europe,79.313,33207.0844 +France,1952,42459667,Europe,67.41,7029.809327 +France,1957,44310863,Europe,68.93,8662.834898 +France,1962,47124000,Europe,70.51,10560.48553 +France,1967,49569000,Europe,71.55,12999.91766 +France,1972,51732000,Europe,72.38,16107.19171 +France,1977,53165019,Europe,73.83,18292.63514 +France,1982,54433565,Europe,74.89,20293.89746 +France,1987,55630100,Europe,76.34,22066.44214 +France,1992,57374179,Europe,77.46,24703.79615 +France,1997,58623428,Europe,78.64,25889.78487 +France,2002,59925035,Europe,79.59,28926.03234 +France,2007,61083916,Europe,80.657,30470.0167 +Gabon,1952,420702,Africa,37.003,4293.476475 +Gabon,1957,434904,Africa,38.999,4976.198099 +Gabon,1962,455661,Africa,40.489,6631.459222 +Gabon,1967,489004,Africa,44.598,8358.761987 +Gabon,1972,537977,Africa,48.69,11401.94841 +Gabon,1977,706367,Africa,52.79,21745.57328 +Gabon,1982,753874,Africa,56.564,15113.36194 +Gabon,1987,880397,Africa,60.19,11864.40844 +Gabon,1992,985739,Africa,61.366,13522.15752 +Gabon,1997,1126189,Africa,60.461,14722.84188 +Gabon,2002,1299304,Africa,56.761,12521.71392 +Gabon,2007,1454867,Africa,56.735,13206.48452 +Gambia,1952,284320,Africa,30,485.2306591 +Gambia,1957,323150,Africa,32.065,520.9267111 +Gambia,1962,374020,Africa,33.896,599.650276 +Gambia,1967,439593,Africa,35.857,734.7829124 +Gambia,1972,517101,Africa,38.308,756.0868363 +Gambia,1977,608274,Africa,41.842,884.7552507 +Gambia,1982,715523,Africa,45.58,835.8096108 +Gambia,1987,848406,Africa,49.265,611.6588611 +Gambia,1992,1025384,Africa,52.644,665.6244126 +Gambia,1997,1235767,Africa,55.861,653.7301704 +Gambia,2002,1457766,Africa,58.041,660.5855997 +Gambia,2007,1688359,Africa,59.448,752.7497265 +Germany,1952,69145952,Europe,67.5,7144.114393 +Germany,1957,71019069,Europe,69.1,10187.82665 +Germany,1962,73739117,Europe,70.3,12902.46291 +Germany,1967,76368453,Europe,70.8,14745.62561 +Germany,1972,78717088,Europe,71,18016.18027 +Germany,1977,78160773,Europe,72.5,20512.92123 +Germany,1982,78335266,Europe,73.8,22031.53274 +Germany,1987,77718298,Europe,74.847,24639.18566 +Germany,1992,80597764,Europe,76.07,26505.30317 +Germany,1997,82011073,Europe,77.34,27788.88416 +Germany,2002,82350671,Europe,78.67,30035.80198 +Germany,2007,82400996,Europe,79.406,32170.37442 +Ghana,1952,5581001,Africa,43.149,911.2989371 +Ghana,1957,6391288,Africa,44.779,1043.561537 +Ghana,1962,7355248,Africa,46.452,1190.041118 +Ghana,1967,8490213,Africa,48.072,1125.69716 +Ghana,1972,9354120,Africa,49.875,1178.223708 +Ghana,1977,10538093,Africa,51.756,993.2239571 +Ghana,1982,11400338,Africa,53.744,876.032569 +Ghana,1987,14168101,Africa,55.729,847.0061135 +Ghana,1992,16278738,Africa,57.501,925.060154 +Ghana,1997,18418288,Africa,58.556,1005.245812 +Ghana,2002,20550751,Africa,58.453,1111.984578 +Ghana,2007,22873338,Africa,60.022,1327.60891 +Greece,1952,7733250,Europe,65.86,3530.690067 +Greece,1957,8096218,Europe,67.86,4916.299889 +Greece,1962,8448233,Europe,69.51,6017.190733 +Greece,1967,8716441,Europe,71,8513.097016 +Greece,1972,8888628,Europe,72.34,12724.82957 +Greece,1977,9308479,Europe,73.68,14195.52428 +Greece,1982,9786480,Europe,75.24,15268.42089 +Greece,1987,9974490,Europe,76.67,16120.52839 +Greece,1992,10325429,Europe,77.03,17541.49634 +Greece,1997,10502372,Europe,77.869,18747.69814 +Greece,2002,10603863,Europe,78.256,22514.2548 +Greece,2007,10706290,Europe,79.483,27538.41188 +Guatemala,1952,3146381,Americas,42.023,2428.237769 +Guatemala,1957,3640876,Americas,44.142,2617.155967 +Guatemala,1962,4208858,Americas,46.954,2750.364446 +Guatemala,1967,4690773,Americas,50.016,3242.531147 +Guatemala,1972,5149581,Americas,53.738,4031.408271 +Guatemala,1977,5703430,Americas,56.029,4879.992748 +Guatemala,1982,6395630,Americas,58.137,4820.49479 +Guatemala,1987,7326406,Americas,60.782,4246.485974 +Guatemala,1992,8486949,Americas,63.373,4439.45084 +Guatemala,1997,9803875,Americas,66.322,4684.313807 +Guatemala,2002,11178650,Americas,68.978,4858.347495 +Guatemala,2007,12572928,Americas,70.259,5186.050003 +Guinea,1952,2664249,Africa,33.609,510.1964923 +Guinea,1957,2876726,Africa,34.558,576.2670245 +Guinea,1962,3140003,Africa,35.753,686.3736739 +Guinea,1967,3451418,Africa,37.197,708.7595409 +Guinea,1972,3811387,Africa,38.842,741.6662307 +Guinea,1977,4227026,Africa,40.762,874.6858643 +Guinea,1982,4710497,Africa,42.891,857.2503577 +Guinea,1987,5650262,Africa,45.552,805.5724718 +Guinea,1992,6990574,Africa,48.576,794.3484384 +Guinea,1997,8048834,Africa,51.455,869.4497668 +Guinea,2002,8807818,Africa,53.676,945.5835837 +Guinea,2007,9947814,Africa,56.007,942.6542111 +Guinea-Bissau,1952,580653,Africa,32.5,299.850319 +Guinea-Bissau,1957,601095,Africa,33.489,431.7904566 +Guinea-Bissau,1962,627820,Africa,34.488,522.0343725 +Guinea-Bissau,1967,601287,Africa,35.492,715.5806402 +Guinea-Bissau,1972,625361,Africa,36.486,820.2245876 +Guinea-Bissau,1977,745228,Africa,37.465,764.7259628 +Guinea-Bissau,1982,825987,Africa,39.327,838.1239671 +Guinea-Bissau,1987,927524,Africa,41.245,736.4153921 +Guinea-Bissau,1992,1050938,Africa,43.266,745.5398706 +Guinea-Bissau,1997,1193708,Africa,44.873,796.6644681 +Guinea-Bissau,2002,1332459,Africa,45.504,575.7047176 +Guinea-Bissau,2007,1472041,Africa,46.388,579.231743 +Haiti,1952,3201488,Americas,37.579,1840.366939 +Haiti,1957,3507701,Americas,40.696,1726.887882 +Haiti,1962,3880130,Americas,43.59,1796.589032 +Haiti,1967,4318137,Americas,46.243,1452.057666 +Haiti,1972,4698301,Americas,48.042,1654.456946 +Haiti,1977,4908554,Americas,49.923,1874.298931 +Haiti,1982,5198399,Americas,51.461,2011.159549 +Haiti,1987,5756203,Americas,53.636,1823.015995 +Haiti,1992,6326682,Americas,55.089,1456.309517 +Haiti,1997,6913545,Americas,56.671,1341.726931 +Haiti,2002,7607651,Americas,58.137,1270.364932 +Haiti,2007,8502814,Americas,60.916,1201.637154 +Honduras,1952,1517453,Americas,41.912,2194.926204 +Honduras,1957,1770390,Americas,44.665,2220.487682 +Honduras,1962,2090162,Americas,48.041,2291.156835 +Honduras,1967,2500689,Americas,50.924,2538.269358 +Honduras,1972,2965146,Americas,53.884,2529.842345 +Honduras,1977,3055235,Americas,57.402,3203.208066 +Honduras,1982,3669448,Americas,60.909,3121.760794 +Honduras,1987,4372203,Americas,64.492,3023.096699 +Honduras,1992,5077347,Americas,66.399,3081.694603 +Honduras,1997,5867957,Americas,67.659,3160.454906 +Honduras,2002,6677328,Americas,68.565,3099.72866 +Honduras,2007,7483763,Americas,70.198,3548.330846 +Hong Kong China,1952,2125900,Asia,60.96,3054.421209 +Hong Kong China,1957,2736300,Asia,64.75,3629.076457 +Hong Kong China,1962,3305200,Asia,67.65,4692.648272 +Hong Kong China,1967,3722800,Asia,70,6197.962814 +Hong Kong China,1972,4115700,Asia,72,8315.928145 +Hong Kong China,1977,4583700,Asia,73.6,11186.14125 +Hong Kong China,1982,5264500,Asia,75.45,14560.53051 +Hong Kong China,1987,5584510,Asia,76.2,20038.47269 +Hong Kong China,1992,5829696,Asia,77.601,24757.60301 +Hong Kong China,1997,6495918,Asia,80,28377.63219 +Hong Kong China,2002,6762476,Asia,81.495,30209.01516 +Hong Kong China,2007,6980412,Asia,82.208,39724.97867 +Hungary,1952,9504000,Europe,64.03,5263.673816 +Hungary,1957,9839000,Europe,66.41,6040.180011 +Hungary,1962,10063000,Europe,67.96,7550.359877 +Hungary,1967,10223422,Europe,69.5,9326.64467 +Hungary,1972,10394091,Europe,69.76,10168.65611 +Hungary,1977,10637171,Europe,69.95,11674.83737 +Hungary,1982,10705535,Europe,69.39,12545.99066 +Hungary,1987,10612740,Europe,69.58,12986.47998 +Hungary,1992,10348684,Europe,69.17,10535.62855 +Hungary,1997,10244684,Europe,71.04,11712.7768 +Hungary,2002,10083313,Europe,72.59,14843.93556 +Hungary,2007,9956108,Europe,73.338,18008.94444 +Iceland,1952,147962,Europe,72.49,7267.688428 +Iceland,1957,165110,Europe,73.47,9244.001412 +Iceland,1962,182053,Europe,73.68,10350.15906 +Iceland,1967,198676,Europe,73.73,13319.89568 +Iceland,1972,209275,Europe,74.46,15798.06362 +Iceland,1977,221823,Europe,76.11,19654.96247 +Iceland,1982,233997,Europe,76.99,23269.6075 +Iceland,1987,244676,Europe,77.23,26923.20628 +Iceland,1992,259012,Europe,78.77,25144.39201 +Iceland,1997,271192,Europe,78.95,28061.09966 +Iceland,2002,288030,Europe,80.5,31163.20196 +Iceland,2007,301931,Europe,81.757,36180.78919 +India,1952,3.72e+08,Asia,37.373,546.5657493 +India,1957,4.09e+08,Asia,40.249,590.061996 +India,1962,4.54e+08,Asia,43.605,658.3471509 +India,1967,5.06e+08,Asia,47.193,700.7706107 +India,1972,5.67e+08,Asia,50.651,724.032527 +India,1977,6.34e+08,Asia,54.208,813.337323 +India,1982,7.08e+08,Asia,56.596,855.7235377 +India,1987,7.88e+08,Asia,58.553,976.5126756 +India,1992,8.72e+08,Asia,60.223,1164.406809 +India,1997,9.59e+08,Asia,61.765,1458.817442 +India,2002,1034172547,Asia,62.879,1746.769454 +India,2007,1110396331,Asia,64.698,2452.210407 +Indonesia,1952,82052000,Asia,37.468,749.6816546 +Indonesia,1957,90124000,Asia,39.918,858.9002707 +Indonesia,1962,99028000,Asia,42.518,849.2897701 +Indonesia,1967,109343000,Asia,45.964,762.4317721 +Indonesia,1972,121282000,Asia,49.203,1111.107907 +Indonesia,1977,136725000,Asia,52.702,1382.702056 +Indonesia,1982,153343000,Asia,56.159,1516.872988 +Indonesia,1987,169276000,Asia,60.137,1748.356961 +Indonesia,1992,184816000,Asia,62.681,2383.140898 +Indonesia,1997,199278000,Asia,66.041,3119.335603 +Indonesia,2002,211060000,Asia,68.588,2873.91287 +Indonesia,2007,223547000,Asia,70.65,3540.651564 +Iran,1952,17272000,Asia,44.869,3035.326002 +Iran,1957,19792000,Asia,47.181,3290.257643 +Iran,1962,22874000,Asia,49.325,4187.329802 +Iran,1967,26538000,Asia,52.469,5906.731805 +Iran,1972,30614000,Asia,55.234,9613.818607 +Iran,1977,35480679,Asia,57.702,11888.59508 +Iran,1982,43072751,Asia,59.62,7608.334602 +Iran,1987,51889696,Asia,63.04,6642.881371 +Iran,1992,60397973,Asia,65.742,7235.653188 +Iran,1997,63327987,Asia,68.042,8263.590301 +Iran,2002,66907826,Asia,69.451,9240.761975 +Iran,2007,69453570,Asia,70.964,11605.71449 +Iraq,1952,5441766,Asia,45.32,4129.766056 +Iraq,1957,6248643,Asia,48.437,6229.333562 +Iraq,1962,7240260,Asia,51.457,8341.737815 +Iraq,1967,8519282,Asia,54.459,8931.459811 +Iraq,1972,10061506,Asia,56.95,9576.037596 +Iraq,1977,11882916,Asia,60.413,14688.23507 +Iraq,1982,14173318,Asia,62.038,14517.90711 +Iraq,1987,16543189,Asia,65.044,11643.57268 +Iraq,1992,17861905,Asia,59.461,3745.640687 +Iraq,1997,20775703,Asia,58.811,3076.239795 +Iraq,2002,24001816,Asia,57.046,4390.717312 +Iraq,2007,27499638,Asia,59.545,4471.061906 +Ireland,1952,2952156,Europe,66.91,5210.280328 +Ireland,1957,2878220,Europe,68.9,5599.077872 +Ireland,1962,2830000,Europe,70.29,6631.597314 +Ireland,1967,2900100,Europe,71.08,7655.568963 +Ireland,1972,3024400,Europe,71.28,9530.772896 +Ireland,1977,3271900,Europe,72.03,11150.98113 +Ireland,1982,3480000,Europe,73.1,12618.32141 +Ireland,1987,3539900,Europe,74.36,13872.86652 +Ireland,1992,3557761,Europe,75.467,17558.81555 +Ireland,1997,3667233,Europe,76.122,24521.94713 +Ireland,2002,3879155,Europe,77.783,34077.04939 +Ireland,2007,4109086,Europe,78.885,40675.99635 +Israel,1952,1620914,Asia,65.39,4086.522128 +Israel,1957,1944401,Asia,67.84,5385.278451 +Israel,1962,2310904,Asia,69.39,7105.630706 +Israel,1967,2693585,Asia,70.75,8393.741404 +Israel,1972,3095893,Asia,71.63,12786.93223 +Israel,1977,3495918,Asia,73.06,13306.61921 +Israel,1982,3858421,Asia,74.45,15367.0292 +Israel,1987,4203148,Asia,75.6,17122.47986 +Israel,1992,4936550,Asia,76.93,18051.52254 +Israel,1997,5531387,Asia,78.269,20896.60924 +Israel,2002,6029529,Asia,79.696,21905.59514 +Israel,2007,6426679,Asia,80.745,25523.2771 +Italy,1952,47666000,Europe,65.94,4931.404155 +Italy,1957,49182000,Europe,67.81,6248.656232 +Italy,1962,50843200,Europe,69.24,8243.58234 +Italy,1967,52667100,Europe,71.06,10022.40131 +Italy,1972,54365564,Europe,72.19,12269.27378 +Italy,1977,56059245,Europe,73.48,14255.98475 +Italy,1982,56535636,Europe,74.98,16537.4835 +Italy,1987,56729703,Europe,76.42,19207.23482 +Italy,1992,56840847,Europe,77.44,22013.64486 +Italy,1997,57479469,Europe,78.82,24675.02446 +Italy,2002,57926999,Europe,80.24,27968.09817 +Italy,2007,58147733,Europe,80.546,28569.7197 +Jamaica,1952,1426095,Americas,58.53,2898.530881 +Jamaica,1957,1535090,Americas,62.61,4756.525781 +Jamaica,1962,1665128,Americas,65.61,5246.107524 +Jamaica,1967,1861096,Americas,67.51,6124.703451 +Jamaica,1972,1997616,Americas,69,7433.889293 +Jamaica,1977,2156814,Americas,70.11,6650.195573 +Jamaica,1982,2298309,Americas,71.21,6068.05135 +Jamaica,1987,2326606,Americas,71.77,6351.237495 +Jamaica,1992,2378618,Americas,71.766,7404.923685 +Jamaica,1997,2531311,Americas,72.262,7121.924704 +Jamaica,2002,2664659,Americas,72.047,6994.774861 +Jamaica,2007,2780132,Americas,72.567,7320.880262 +Japan,1952,86459025,Asia,63.03,3216.956347 +Japan,1957,91563009,Asia,65.5,4317.694365 +Japan,1962,95831757,Asia,68.73,6576.649461 +Japan,1967,100825279,Asia,71.43,9847.788607 +Japan,1972,107188273,Asia,73.42,14778.78636 +Japan,1977,113872473,Asia,75.38,16610.37701 +Japan,1982,118454974,Asia,77.11,19384.10571 +Japan,1987,122091325,Asia,78.67,22375.94189 +Japan,1992,124329269,Asia,79.36,26824.89511 +Japan,1997,125956499,Asia,80.69,28816.58499 +Japan,2002,127065841,Asia,82,28604.5919 +Japan,2007,127467972,Asia,82.603,31656.06806 +Jordan,1952,607914,Asia,43.158,1546.907807 +Jordan,1957,746559,Asia,45.669,1886.080591 +Jordan,1962,933559,Asia,48.126,2348.009158 +Jordan,1967,1255058,Asia,51.629,2741.796252 +Jordan,1972,1613551,Asia,56.528,2110.856309 +Jordan,1977,1937652,Asia,61.134,2852.351568 +Jordan,1982,2347031,Asia,63.739,4161.415959 +Jordan,1987,2820042,Asia,65.869,4448.679912 +Jordan,1992,3867409,Asia,68.015,3431.593647 +Jordan,1997,4526235,Asia,69.772,3645.379572 +Jordan,2002,5307470,Asia,71.263,3844.917194 +Jordan,2007,6053193,Asia,72.535,4519.461171 +Kenya,1952,6464046,Africa,42.27,853.540919 +Kenya,1957,7454779,Africa,44.686,944.4383152 +Kenya,1962,8678557,Africa,47.949,896.9663732 +Kenya,1967,10191512,Africa,50.654,1056.736457 +Kenya,1972,12044785,Africa,53.559,1222.359968 +Kenya,1977,14500404,Africa,56.155,1267.613204 +Kenya,1982,17661452,Africa,58.766,1348.225791 +Kenya,1987,21198082,Africa,59.339,1361.936856 +Kenya,1992,25020539,Africa,59.285,1341.921721 +Kenya,1997,28263827,Africa,54.407,1360.485021 +Kenya,2002,31386842,Africa,50.992,1287.514732 +Kenya,2007,35610177,Africa,54.11,1463.249282 +Korea Dem. Rep.,1952,8865488,Asia,50.056,1088.277758 +Korea Dem. Rep.,1957,9411381,Asia,54.081,1571.134655 +Korea Dem. Rep.,1962,10917494,Asia,56.656,1621.693598 +Korea Dem. Rep.,1967,12617009,Asia,59.942,2143.540609 +Korea Dem. Rep.,1972,14781241,Asia,63.983,3701.621503 +Korea Dem. Rep.,1977,16325320,Asia,67.159,4106.301249 +Korea Dem. Rep.,1982,17647518,Asia,69.1,4106.525293 +Korea Dem. Rep.,1987,19067554,Asia,70.647,4106.492315 +Korea Dem. Rep.,1992,20711375,Asia,69.978,3726.063507 +Korea Dem. Rep.,1997,21585105,Asia,67.727,1690.756814 +Korea Dem. Rep.,2002,22215365,Asia,66.662,1646.758151 +Korea Dem. Rep.,2007,23301725,Asia,67.297,1593.06548 +Korea Rep.,1952,20947571,Asia,47.453,1030.592226 +Korea Rep.,1957,22611552,Asia,52.681,1487.593537 +Korea Rep.,1962,26420307,Asia,55.292,1536.344387 +Korea Rep.,1967,30131000,Asia,57.716,2029.228142 +Korea Rep.,1972,33505000,Asia,62.612,3030.87665 +Korea Rep.,1977,36436000,Asia,64.766,4657.22102 +Korea Rep.,1982,39326000,Asia,67.123,5622.942464 +Korea Rep.,1987,41622000,Asia,69.81,8533.088805 +Korea Rep.,1992,43805450,Asia,72.244,12104.27872 +Korea Rep.,1997,46173816,Asia,74.647,15993.52796 +Korea Rep.,2002,47969150,Asia,77.045,19233.98818 +Korea Rep.,2007,49044790,Asia,78.623,23348.13973 +Kuwait,1952,160000,Asia,55.565,108382.3529 +Kuwait,1957,212846,Asia,58.033,113523.1329 +Kuwait,1962,358266,Asia,60.47,95458.11176 +Kuwait,1967,575003,Asia,64.624,80894.88326 +Kuwait,1972,841934,Asia,67.712,109347.867 +Kuwait,1977,1140357,Asia,69.343,59265.47714 +Kuwait,1982,1497494,Asia,71.309,31354.03573 +Kuwait,1987,1891487,Asia,74.174,28118.42998 +Kuwait,1992,1418095,Asia,75.19,34932.91959 +Kuwait,1997,1765345,Asia,76.156,40300.61996 +Kuwait,2002,2111561,Asia,76.904,35110.10566 +Kuwait,2007,2505559,Asia,77.588,47306.98978 +Lebanon,1952,1439529,Asia,55.928,4834.804067 +Lebanon,1957,1647412,Asia,59.489,6089.786934 +Lebanon,1962,1886848,Asia,62.094,5714.560611 +Lebanon,1967,2186894,Asia,63.87,6006.983042 +Lebanon,1972,2680018,Asia,65.421,7486.384341 +Lebanon,1977,3115787,Asia,66.099,8659.696836 +Lebanon,1982,3086876,Asia,66.983,7640.519521 +Lebanon,1987,3089353,Asia,67.926,5377.091329 +Lebanon,1992,3219994,Asia,69.292,6890.806854 +Lebanon,1997,3430388,Asia,70.265,8754.96385 +Lebanon,2002,3677780,Asia,71.028,9313.93883 +Lebanon,2007,3921278,Asia,71.993,10461.05868 +Lesotho,1952,748747,Africa,42.138,298.8462121 +Lesotho,1957,813338,Africa,45.047,335.9971151 +Lesotho,1962,893143,Africa,47.747,411.8006266 +Lesotho,1967,996380,Africa,48.492,498.6390265 +Lesotho,1972,1116779,Africa,49.767,496.5815922 +Lesotho,1977,1251524,Africa,52.208,745.3695408 +Lesotho,1982,1411807,Africa,55.078,797.2631074 +Lesotho,1987,1599200,Africa,57.18,773.9932141 +Lesotho,1992,1803195,Africa,59.685,977.4862725 +Lesotho,1997,1982823,Africa,55.558,1186.147994 +Lesotho,2002,2046772,Africa,44.593,1275.184575 +Lesotho,2007,2012649,Africa,42.592,1569.331442 +Liberia,1952,863308,Africa,38.48,575.5729961 +Liberia,1957,975950,Africa,39.486,620.9699901 +Liberia,1962,1112796,Africa,40.502,634.1951625 +Liberia,1967,1279406,Africa,41.536,713.6036483 +Liberia,1972,1482628,Africa,42.614,803.0054535 +Liberia,1977,1703617,Africa,43.764,640.3224383 +Liberia,1982,1956875,Africa,44.852,572.1995694 +Liberia,1987,2269414,Africa,46.027,506.1138573 +Liberia,1992,1912974,Africa,40.802,636.6229191 +Liberia,1997,2200725,Africa,42.221,609.1739508 +Liberia,2002,2814651,Africa,43.753,531.4823679 +Liberia,2007,3193942,Africa,45.678,414.5073415 +Libya,1952,1019729,Africa,42.723,2387.54806 +Libya,1957,1201578,Africa,45.289,3448.284395 +Libya,1962,1441863,Africa,47.808,6757.030816 +Libya,1967,1759224,Africa,50.227,18772.75169 +Libya,1972,2183877,Africa,52.773,21011.49721 +Libya,1977,2721783,Africa,57.442,21951.21176 +Libya,1982,3344074,Africa,62.155,17364.27538 +Libya,1987,3799845,Africa,66.234,11770.5898 +Libya,1992,4364501,Africa,68.755,9640.138501 +Libya,1997,4759670,Africa,71.555,9467.446056 +Libya,2002,5368585,Africa,72.737,9534.677467 +Libya,2007,6036914,Africa,73.952,12057.49928 +Madagascar,1952,4762912,Africa,36.681,1443.011715 +Madagascar,1957,5181679,Africa,38.865,1589.20275 +Madagascar,1962,5703324,Africa,40.848,1643.38711 +Madagascar,1967,6334556,Africa,42.881,1634.047282 +Madagascar,1972,7082430,Africa,44.851,1748.562982 +Madagascar,1977,8007166,Africa,46.881,1544.228586 +Madagascar,1982,9171477,Africa,48.969,1302.878658 +Madagascar,1987,10568642,Africa,49.35,1155.441948 +Madagascar,1992,12210395,Africa,52.214,1040.67619 +Madagascar,1997,14165114,Africa,54.978,986.2958956 +Madagascar,2002,16473477,Africa,57.286,894.6370822 +Madagascar,2007,19167654,Africa,59.443,1044.770126 +Malawi,1952,2917802,Africa,36.256,369.1650802 +Malawi,1957,3221238,Africa,37.207,416.3698064 +Malawi,1962,3628608,Africa,38.41,427.9010856 +Malawi,1967,4147252,Africa,39.487,495.5147806 +Malawi,1972,4730997,Africa,41.766,584.6219709 +Malawi,1977,5637246,Africa,43.767,663.2236766 +Malawi,1982,6502825,Africa,45.642,632.8039209 +Malawi,1987,7824747,Africa,47.457,635.5173634 +Malawi,1992,10014249,Africa,49.42,563.2000145 +Malawi,1997,10419991,Africa,47.495,692.2758103 +Malawi,2002,11824495,Africa,45.009,665.4231186 +Malawi,2007,13327079,Africa,48.303,759.3499101 +Malaysia,1952,6748378,Asia,48.463,1831.132894 +Malaysia,1957,7739235,Asia,52.102,1810.066992 +Malaysia,1962,8906385,Asia,55.737,2036.884944 +Malaysia,1967,10154878,Asia,59.371,2277.742396 +Malaysia,1972,11441462,Asia,63.01,2849.09478 +Malaysia,1977,12845381,Asia,65.256,3827.921571 +Malaysia,1982,14441916,Asia,68,4920.355951 +Malaysia,1987,16331785,Asia,69.5,5249.802653 +Malaysia,1992,18319502,Asia,70.693,7277.912802 +Malaysia,1997,20476091,Asia,71.938,10132.90964 +Malaysia,2002,22662365,Asia,73.044,10206.97794 +Malaysia,2007,24821286,Asia,74.241,12451.6558 +Mali,1952,3838168,Africa,33.685,452.3369807 +Mali,1957,4241884,Africa,35.307,490.3821867 +Mali,1962,4690372,Africa,36.936,496.1743428 +Mali,1967,5212416,Africa,38.487,545.0098873 +Mali,1972,5828158,Africa,39.977,581.3688761 +Mali,1977,6491649,Africa,41.714,686.3952693 +Mali,1982,6998256,Africa,43.916,618.0140641 +Mali,1987,7634008,Africa,46.364,684.1715576 +Mali,1992,8416215,Africa,48.388,739.014375 +Mali,1997,9384984,Africa,49.903,790.2579846 +Mali,2002,10580176,Africa,51.818,951.4097518 +Mali,2007,12031795,Africa,54.467,1042.581557 +Mauritania,1952,1022556,Africa,40.543,743.1159097 +Mauritania,1957,1076852,Africa,42.338,846.1202613 +Mauritania,1962,1146757,Africa,44.248,1055.896036 +Mauritania,1967,1230542,Africa,46.289,1421.145193 +Mauritania,1972,1332786,Africa,48.437,1586.851781 +Mauritania,1977,1456688,Africa,50.852,1497.492223 +Mauritania,1982,1622136,Africa,53.599,1481.150189 +Mauritania,1987,1841240,Africa,56.145,1421.603576 +Mauritania,1992,2119465,Africa,58.333,1361.369784 +Mauritania,1997,2444741,Africa,60.43,1483.136136 +Mauritania,2002,2828858,Africa,62.247,1579.019543 +Mauritania,2007,3270065,Africa,64.164,1803.151496 +Mauritius,1952,516556,Africa,50.986,1967.955707 +Mauritius,1957,609816,Africa,58.089,2034.037981 +Mauritius,1962,701016,Africa,60.246,2529.067487 +Mauritius,1967,789309,Africa,61.557,2475.387562 +Mauritius,1972,851334,Africa,62.944,2575.484158 +Mauritius,1977,913025,Africa,64.93,3710.982963 +Mauritius,1982,992040,Africa,66.711,3688.037739 +Mauritius,1987,1042663,Africa,68.74,4783.586903 +Mauritius,1992,1096202,Africa,69.745,6058.253846 +Mauritius,1997,1149818,Africa,70.736,7425.705295 +Mauritius,2002,1200206,Africa,71.954,9021.815894 +Mauritius,2007,1250882,Africa,72.801,10956.99112 +Mexico,1952,30144317,Americas,50.789,3478.125529 +Mexico,1957,35015548,Americas,55.19,4131.546641 +Mexico,1962,41121485,Americas,58.299,4581.609385 +Mexico,1967,47995559,Americas,60.11,5754.733883 +Mexico,1972,55984294,Americas,62.361,6809.40669 +Mexico,1977,63759976,Americas,65.032,7674.929108 +Mexico,1982,71640904,Americas,67.405,9611.147541 +Mexico,1987,80122492,Americas,69.498,8688.156003 +Mexico,1992,88111030,Americas,71.455,9472.384295 +Mexico,1997,95895146,Americas,73.67,9767.29753 +Mexico,2002,102479927,Americas,74.902,10742.44053 +Mexico,2007,108700891,Americas,76.195,11977.57496 +Mongolia,1952,800663,Asia,42.244,786.5668575 +Mongolia,1957,882134,Asia,45.248,912.6626085 +Mongolia,1962,1010280,Asia,48.251,1056.353958 +Mongolia,1967,1149500,Asia,51.253,1226.04113 +Mongolia,1972,1320500,Asia,53.754,1421.741975 +Mongolia,1977,1528000,Asia,55.491,1647.511665 +Mongolia,1982,1756032,Asia,57.489,2000.603139 +Mongolia,1987,2015133,Asia,60.222,2338.008304 +Mongolia,1992,2312802,Asia,61.271,1785.402016 +Mongolia,1997,2494803,Asia,63.625,1902.2521 +Mongolia,2002,2674234,Asia,65.033,2140.739323 +Mongolia,2007,2874127,Asia,66.803,3095.772271 +Montenegro,1952,413834,Europe,59.164,2647.585601 +Montenegro,1957,442829,Europe,61.448,3682.259903 +Montenegro,1962,474528,Europe,63.728,4649.593785 +Montenegro,1967,501035,Europe,67.178,5907.850937 +Montenegro,1972,527678,Europe,70.636,7778.414017 +Montenegro,1977,560073,Europe,73.066,9595.929905 +Montenegro,1982,562548,Europe,74.101,11222.58762 +Montenegro,1987,569473,Europe,74.865,11732.51017 +Montenegro,1992,621621,Europe,75.435,7003.339037 +Montenegro,1997,692651,Europe,75.445,6465.613349 +Montenegro,2002,720230,Europe,73.981,6557.194282 +Montenegro,2007,684736,Europe,74.543,9253.896111 +Morocco,1952,9939217,Africa,42.873,1688.20357 +Morocco,1957,11406350,Africa,45.423,1642.002314 +Morocco,1962,13056604,Africa,47.924,1566.353493 +Morocco,1967,14770296,Africa,50.335,1711.04477 +Morocco,1972,16660670,Africa,52.862,1930.194975 +Morocco,1977,18396941,Africa,55.73,2370.619976 +Morocco,1982,20198730,Africa,59.65,2702.620356 +Morocco,1987,22987397,Africa,62.677,2755.046991 +Morocco,1992,25798239,Africa,65.393,2948.047252 +Morocco,1997,28529501,Africa,67.66,2982.101858 +Morocco,2002,31167783,Africa,69.615,3258.495584 +Morocco,2007,33757175,Africa,71.164,3820.17523 +Mozambique,1952,6446316,Africa,31.286,468.5260381 +Mozambique,1957,7038035,Africa,33.779,495.5868333 +Mozambique,1962,7788944,Africa,36.161,556.6863539 +Mozambique,1967,8680909,Africa,38.113,566.6691539 +Mozambique,1972,9809596,Africa,40.328,724.9178037 +Mozambique,1977,11127868,Africa,42.495,502.3197334 +Mozambique,1982,12587223,Africa,42.795,462.2114149 +Mozambique,1987,12891952,Africa,42.861,389.8761846 +Mozambique,1992,13160731,Africa,44.284,410.8968239 +Mozambique,1997,16603334,Africa,46.344,472.3460771 +Mozambique,2002,18473780,Africa,44.026,633.6179466 +Mozambique,2007,19951656,Africa,42.082,823.6856205 +Myanmar,1952,20092996,Asia,36.319,331 +Myanmar,1957,21731844,Asia,41.905,350 +Myanmar,1962,23634436,Asia,45.108,388 +Myanmar,1967,25870271,Asia,49.379,349 +Myanmar,1972,28466390,Asia,53.07,357 +Myanmar,1977,31528087,Asia,56.059,371 +Myanmar,1982,34680442,Asia,58.056,424 +Myanmar,1987,38028578,Asia,58.339,385 +Myanmar,1992,40546538,Asia,59.32,347 +Myanmar,1997,43247867,Asia,60.328,415 +Myanmar,2002,45598081,Asia,59.908,611 +Myanmar,2007,47761980,Asia,62.069,944 +Namibia,1952,485831,Africa,41.725,2423.780443 +Namibia,1957,548080,Africa,45.226,2621.448058 +Namibia,1962,621392,Africa,48.386,3173.215595 +Namibia,1967,706640,Africa,51.159,3793.694753 +Namibia,1972,821782,Africa,53.867,3746.080948 +Namibia,1977,977026,Africa,56.437,3876.485958 +Namibia,1982,1099010,Africa,58.968,4191.100511 +Namibia,1987,1278184,Africa,60.835,3693.731337 +Namibia,1992,1554253,Africa,61.999,3804.537999 +Namibia,1997,1774766,Africa,58.909,3899.52426 +Namibia,2002,1972153,Africa,51.479,4072.324751 +Namibia,2007,2055080,Africa,52.906,4811.060429 +Nepal,1952,9182536,Asia,36.157,545.8657229 +Nepal,1957,9682338,Asia,37.686,597.9363558 +Nepal,1962,10332057,Asia,39.393,652.3968593 +Nepal,1967,11261690,Asia,41.472,676.4422254 +Nepal,1972,12412593,Asia,43.971,674.7881296 +Nepal,1977,13933198,Asia,46.748,694.1124398 +Nepal,1982,15796314,Asia,49.594,718.3730947 +Nepal,1987,17917180,Asia,52.537,775.6324501 +Nepal,1992,20326209,Asia,55.727,897.7403604 +Nepal,1997,23001113,Asia,59.426,1010.892138 +Nepal,2002,25873917,Asia,61.34,1057.206311 +Nepal,2007,28901790,Asia,63.785,1091.359778 +Netherlands,1952,10381988,Europe,72.13,8941.571858 +Netherlands,1957,11026383,Europe,72.99,11276.19344 +Netherlands,1962,11805689,Europe,73.23,12790.84956 +Netherlands,1967,12596822,Europe,73.82,15363.25136 +Netherlands,1972,13329874,Europe,73.75,18794.74567 +Netherlands,1977,13852989,Europe,75.24,21209.0592 +Netherlands,1982,14310401,Europe,76.05,21399.46046 +Netherlands,1987,14665278,Europe,76.83,23651.32361 +Netherlands,1992,15174244,Europe,77.42,26790.94961 +Netherlands,1997,15604464,Europe,78.03,30246.13063 +Netherlands,2002,16122830,Europe,78.53,33724.75778 +Netherlands,2007,16570613,Europe,79.762,36797.93332 +New Zealand,1952,1994794,Oceania,69.39,10556.57566 +New Zealand,1957,2229407,Oceania,70.26,12247.39532 +New Zealand,1962,2488550,Oceania,71.24,13175.678 +New Zealand,1967,2728150,Oceania,71.52,14463.91893 +New Zealand,1972,2929100,Oceania,71.89,16046.03728 +New Zealand,1977,3164900,Oceania,72.22,16233.7177 +New Zealand,1982,3210650,Oceania,73.84,17632.4104 +New Zealand,1987,3317166,Oceania,74.32,19007.19129 +New Zealand,1992,3437674,Oceania,76.33,18363.32494 +New Zealand,1997,3676187,Oceania,77.55,21050.41377 +New Zealand,2002,3908037,Oceania,79.11,23189.80135 +New Zealand,2007,4115771,Oceania,80.204,25185.00911 +Nicaragua,1952,1165790,Americas,42.314,3112.363948 +Nicaragua,1957,1358828,Americas,45.432,3457.415947 +Nicaragua,1962,1590597,Americas,48.632,3634.364406 +Nicaragua,1967,1865490,Americas,51.884,4643.393534 +Nicaragua,1972,2182908,Americas,55.151,4688.593267 +Nicaragua,1977,2554598,Americas,57.47,5486.371089 +Nicaragua,1982,2979423,Americas,59.298,3470.338156 +Nicaragua,1987,3344353,Americas,62.008,2955.984375 +Nicaragua,1992,4017939,Americas,65.843,2170.151724 +Nicaragua,1997,4609572,Americas,68.426,2253.023004 +Nicaragua,2002,5146848,Americas,70.836,2474.548819 +Nicaragua,2007,5675356,Americas,72.899,2749.320965 +Niger,1952,3379468,Africa,37.444,761.879376 +Niger,1957,3692184,Africa,38.598,835.5234025 +Niger,1962,4076008,Africa,39.487,997.7661127 +Niger,1967,4534062,Africa,40.118,1054.384891 +Niger,1972,5060262,Africa,40.546,954.2092363 +Niger,1977,5682086,Africa,41.291,808.8970728 +Niger,1982,6437188,Africa,42.598,909.7221354 +Niger,1987,7332638,Africa,44.555,668.3000228 +Niger,1992,8392818,Africa,47.391,581.182725 +Niger,1997,9666252,Africa,51.313,580.3052092 +Niger,2002,11140655,Africa,54.496,601.0745012 +Niger,2007,12894865,Africa,56.867,619.6768924 +Nigeria,1952,33119096,Africa,36.324,1077.281856 +Nigeria,1957,37173340,Africa,37.802,1100.592563 +Nigeria,1962,41871351,Africa,39.36,1150.927478 +Nigeria,1967,47287752,Africa,41.04,1014.514104 +Nigeria,1972,53740085,Africa,42.821,1698.388838 +Nigeria,1977,62209173,Africa,44.514,1981.951806 +Nigeria,1982,73039376,Africa,45.826,1576.97375 +Nigeria,1987,81551520,Africa,46.886,1385.029563 +Nigeria,1992,93364244,Africa,47.472,1619.848217 +Nigeria,1997,106207839,Africa,47.464,1624.941275 +Nigeria,2002,119901274,Africa,46.608,1615.286395 +Nigeria,2007,135031164,Africa,46.859,2013.977305 +Norway,1952,3327728,Europe,72.67,10095.42172 +Norway,1957,3491938,Europe,73.44,11653.97304 +Norway,1962,3638919,Europe,73.47,13450.40151 +Norway,1967,3786019,Europe,74.08,16361.87647 +Norway,1972,3933004,Europe,74.34,18965.05551 +Norway,1977,4043205,Europe,75.37,23311.34939 +Norway,1982,4114787,Europe,75.97,26298.63531 +Norway,1987,4186147,Europe,75.89,31540.9748 +Norway,1992,4286357,Europe,77.32,33965.66115 +Norway,1997,4405672,Europe,78.32,41283.16433 +Norway,2002,4535591,Europe,79.05,44683.97525 +Norway,2007,4627926,Europe,80.196,49357.19017 +Oman,1952,507833,Asia,37.578,1828.230307 +Oman,1957,561977,Asia,40.08,2242.746551 +Oman,1962,628164,Asia,43.165,2924.638113 +Oman,1967,714775,Asia,46.988,4720.942687 +Oman,1972,829050,Asia,52.143,10618.03855 +Oman,1977,1004533,Asia,57.367,11848.34392 +Oman,1982,1301048,Asia,62.728,12954.79101 +Oman,1987,1593882,Asia,67.734,18115.22313 +Oman,1992,1915208,Asia,71.197,18616.70691 +Oman,1997,2283635,Asia,72.499,19702.05581 +Oman,2002,2713462,Asia,74.193,19774.83687 +Oman,2007,3204897,Asia,75.64,22316.19287 +Pakistan,1952,41346560,Asia,43.436,684.5971438 +Pakistan,1957,46679944,Asia,45.557,747.0835292 +Pakistan,1962,53100671,Asia,47.67,803.3427418 +Pakistan,1967,60641899,Asia,49.8,942.4082588 +Pakistan,1972,69325921,Asia,51.929,1049.938981 +Pakistan,1977,78152686,Asia,54.043,1175.921193 +Pakistan,1982,91462088,Asia,56.158,1443.429832 +Pakistan,1987,105186881,Asia,58.245,1704.686583 +Pakistan,1992,120065004,Asia,60.838,1971.829464 +Pakistan,1997,135564834,Asia,61.818,2049.350521 +Pakistan,2002,153403524,Asia,63.61,2092.712441 +Pakistan,2007,169270617,Asia,65.483,2605.94758 +Panama,1952,940080,Americas,55.191,2480.380334 +Panama,1957,1063506,Americas,59.201,2961.800905 +Panama,1962,1215725,Americas,61.817,3536.540301 +Panama,1967,1405486,Americas,64.071,4421.009084 +Panama,1972,1616384,Americas,66.216,5364.249663 +Panama,1977,1839782,Americas,68.681,5351.912144 +Panama,1982,2036305,Americas,70.472,7009.601598 +Panama,1987,2253639,Americas,71.523,7034.779161 +Panama,1992,2484997,Americas,72.462,6618.74305 +Panama,1997,2734531,Americas,73.738,7113.692252 +Panama,2002,2990875,Americas,74.712,7356.031934 +Panama,2007,3242173,Americas,75.537,9809.185636 +Paraguay,1952,1555876,Americas,62.649,1952.308701 +Paraguay,1957,1770902,Americas,63.196,2046.154706 +Paraguay,1962,2009813,Americas,64.361,2148.027146 +Paraguay,1967,2287985,Americas,64.951,2299.376311 +Paraguay,1972,2614104,Americas,65.815,2523.337977 +Paraguay,1977,2984494,Americas,66.353,3248.373311 +Paraguay,1982,3366439,Americas,66.874,4258.503604 +Paraguay,1987,3886512,Americas,67.378,3998.875695 +Paraguay,1992,4483945,Americas,68.225,4196.411078 +Paraguay,1997,5154123,Americas,69.4,4247.400261 +Paraguay,2002,5884491,Americas,70.755,3783.674243 +Paraguay,2007,6667147,Americas,71.752,4172.838464 +Peru,1952,8025700,Americas,43.902,3758.523437 +Peru,1957,9146100,Americas,46.263,4245.256698 +Peru,1962,10516500,Americas,49.096,4957.037982 +Peru,1967,12132200,Americas,51.445,5788.09333 +Peru,1972,13954700,Americas,55.448,5937.827283 +Peru,1977,15990099,Americas,58.447,6281.290855 +Peru,1982,18125129,Americas,61.406,6434.501797 +Peru,1987,20195924,Americas,64.134,6360.943444 +Peru,1992,22430449,Americas,66.458,4446.380924 +Peru,1997,24748122,Americas,68.386,5838.347657 +Peru,2002,26769436,Americas,69.906,5909.020073 +Peru,2007,28674757,Americas,71.421,7408.905561 +Philippines,1952,22438691,Asia,47.752,1272.880995 +Philippines,1957,26072194,Asia,51.334,1547.944844 +Philippines,1962,30325264,Asia,54.757,1649.552153 +Philippines,1967,35356600,Asia,56.393,1814.12743 +Philippines,1972,40850141,Asia,58.065,1989.37407 +Philippines,1977,46850962,Asia,60.06,2373.204287 +Philippines,1982,53456774,Asia,62.082,2603.273765 +Philippines,1987,60017788,Asia,64.151,2189.634995 +Philippines,1992,67185766,Asia,66.458,2279.324017 +Philippines,1997,75012988,Asia,68.564,2536.534925 +Philippines,2002,82995088,Asia,70.303,2650.921068 +Philippines,2007,91077287,Asia,71.688,3190.481016 +Poland,1952,25730551,Europe,61.31,4029.329699 +Poland,1957,28235346,Europe,65.77,4734.253019 +Poland,1962,30329617,Europe,67.64,5338.752143 +Poland,1967,31785378,Europe,69.61,6557.152776 +Poland,1972,33039545,Europe,70.85,8006.506993 +Poland,1977,34621254,Europe,70.67,9508.141454 +Poland,1982,36227381,Europe,71.32,8451.531004 +Poland,1987,37740710,Europe,70.98,9082.351172 +Poland,1992,38370697,Europe,70.99,7738.881247 +Poland,1997,38654957,Europe,72.75,10159.58368 +Poland,2002,38625976,Europe,74.67,12002.23908 +Poland,2007,38518241,Europe,75.563,15389.92468 +Portugal,1952,8526050,Europe,59.82,3068.319867 +Portugal,1957,8817650,Europe,61.51,3774.571743 +Portugal,1962,9019800,Europe,64.39,4727.954889 +Portugal,1967,9103000,Europe,66.6,6361.517993 +Portugal,1972,8970450,Europe,69.26,9022.247417 +Portugal,1977,9662600,Europe,70.41,10172.48572 +Portugal,1982,9859650,Europe,72.77,11753.84291 +Portugal,1987,9915289,Europe,74.06,13039.30876 +Portugal,1992,9927680,Europe,74.86,16207.26663 +Portugal,1997,10156415,Europe,75.97,17641.03156 +Portugal,2002,10433867,Europe,77.29,19970.90787 +Portugal,2007,10642836,Europe,78.098,20509.64777 +Puerto Rico,1952,2227000,Americas,64.28,3081.959785 +Puerto Rico,1957,2260000,Americas,68.54,3907.156189 +Puerto Rico,1962,2448046,Americas,69.62,5108.34463 +Puerto Rico,1967,2648961,Americas,71.1,6929.277714 +Puerto Rico,1972,2847132,Americas,72.16,9123.041742 +Puerto Rico,1977,3080828,Americas,73.44,9770.524921 +Puerto Rico,1982,3279001,Americas,73.75,10330.98915 +Puerto Rico,1987,3444468,Americas,74.63,12281.34191 +Puerto Rico,1992,3585176,Americas,73.911,14641.58711 +Puerto Rico,1997,3759430,Americas,74.917,16999.4333 +Puerto Rico,2002,3859606,Americas,77.778,18855.60618 +Puerto Rico,2007,3942491,Americas,78.746,19328.70901 +Reunion,1952,257700,Africa,52.724,2718.885295 +Reunion,1957,308700,Africa,55.09,2769.451844 +Reunion,1962,358900,Africa,57.666,3173.72334 +Reunion,1967,414024,Africa,60.542,4021.175739 +Reunion,1972,461633,Africa,64.274,5047.658563 +Reunion,1977,492095,Africa,67.064,4319.804067 +Reunion,1982,517810,Africa,69.885,5267.219353 +Reunion,1987,562035,Africa,71.913,5303.377488 +Reunion,1992,622191,Africa,73.615,6101.255823 +Reunion,1997,684810,Africa,74.772,6071.941411 +Reunion,2002,743981,Africa,75.744,6316.1652 +Reunion,2007,798094,Africa,76.442,7670.122558 +Romania,1952,16630000,Europe,61.05,3144.613186 +Romania,1957,17829327,Europe,64.1,3943.370225 +Romania,1962,18680721,Europe,66.8,4734.997586 +Romania,1967,19284814,Europe,66.8,6470.866545 +Romania,1972,20662648,Europe,69.21,8011.414402 +Romania,1977,21658597,Europe,69.46,9356.39724 +Romania,1982,22356726,Europe,69.66,9605.314053 +Romania,1987,22686371,Europe,69.53,9696.273295 +Romania,1992,22797027,Europe,69.36,6598.409903 +Romania,1997,22562458,Europe,69.72,7346.547557 +Romania,2002,22404337,Europe,71.322,7885.360081 +Romania,2007,22276056,Europe,72.476,10808.47561 +Rwanda,1952,2534927,Africa,40,493.3238752 +Rwanda,1957,2822082,Africa,41.5,540.2893983 +Rwanda,1962,3051242,Africa,43,597.4730727 +Rwanda,1967,3451079,Africa,44.1,510.9637142 +Rwanda,1972,3992121,Africa,44.6,590.5806638 +Rwanda,1977,4657072,Africa,45,670.0806011 +Rwanda,1982,5507565,Africa,46.218,881.5706467 +Rwanda,1987,6349365,Africa,44.02,847.991217 +Rwanda,1992,7290203,Africa,23.599,737.0685949 +Rwanda,1997,7212583,Africa,36.087,589.9445051 +Rwanda,2002,7852401,Africa,43.413,785.6537648 +Rwanda,2007,8860588,Africa,46.242,863.0884639 +Sao Tome and Principe,1952,60011,Africa,46.471,879.5835855 +Sao Tome and Principe,1957,61325,Africa,48.945,860.7369026 +Sao Tome and Principe,1962,65345,Africa,51.893,1071.551119 +Sao Tome and Principe,1967,70787,Africa,54.425,1384.840593 +Sao Tome and Principe,1972,76595,Africa,56.48,1532.985254 +Sao Tome and Principe,1977,86796,Africa,58.55,1737.561657 +Sao Tome and Principe,1982,98593,Africa,60.351,1890.218117 +Sao Tome and Principe,1987,110812,Africa,61.728,1516.525457 +Sao Tome and Principe,1992,125911,Africa,62.742,1428.777814 +Sao Tome and Principe,1997,145608,Africa,63.306,1339.076036 +Sao Tome and Principe,2002,170372,Africa,64.337,1353.09239 +Sao Tome and Principe,2007,199579,Africa,65.528,1598.435089 +Saudi Arabia,1952,4005677,Asia,39.875,6459.554823 +Saudi Arabia,1957,4419650,Asia,42.868,8157.591248 +Saudi Arabia,1962,4943029,Asia,45.914,11626.41975 +Saudi Arabia,1967,5618198,Asia,49.901,16903.04886 +Saudi Arabia,1972,6472756,Asia,53.886,24837.42865 +Saudi Arabia,1977,8128505,Asia,58.69,34167.7626 +Saudi Arabia,1982,11254672,Asia,63.012,33693.17525 +Saudi Arabia,1987,14619745,Asia,66.295,21198.26136 +Saudi Arabia,1992,16945857,Asia,68.768,24841.61777 +Saudi Arabia,1997,21229759,Asia,70.533,20586.69019 +Saudi Arabia,2002,24501530,Asia,71.626,19014.54118 +Saudi Arabia,2007,27601038,Asia,72.777,21654.83194 +Senegal,1952,2755589,Africa,37.278,1450.356983 +Senegal,1957,3054547,Africa,39.329,1567.653006 +Senegal,1962,3430243,Africa,41.454,1654.988723 +Senegal,1967,3965841,Africa,43.563,1612.404632 +Senegal,1972,4588696,Africa,45.815,1597.712056 +Senegal,1977,5260855,Africa,48.879,1561.769116 +Senegal,1982,6147783,Africa,52.379,1518.479984 +Senegal,1987,7171347,Africa,55.769,1441.72072 +Senegal,1992,8307920,Africa,58.196,1367.899369 +Senegal,1997,9535314,Africa,60.187,1392.368347 +Senegal,2002,10870037,Africa,61.6,1519.635262 +Senegal,2007,12267493,Africa,63.062,1712.472136 +Serbia,1952,6860147,Europe,57.996,3581.459448 +Serbia,1957,7271135,Europe,61.685,4981.090891 +Serbia,1962,7616060,Europe,64.531,6289.629157 +Serbia,1967,7971222,Europe,66.914,7991.707066 +Serbia,1972,8313288,Europe,68.7,10522.06749 +Serbia,1977,8686367,Europe,70.3,12980.66956 +Serbia,1982,9032824,Europe,70.162,15181.0927 +Serbia,1987,9230783,Europe,71.218,15870.87851 +Serbia,1992,9826397,Europe,71.659,9325.068238 +Serbia,1997,10336594,Europe,72.232,7914.320304 +Serbia,2002,10111559,Europe,73.213,7236.075251 +Serbia,2007,10150265,Europe,74.002,9786.534714 +Sierra Leone,1952,2143249,Africa,30.331,879.7877358 +Sierra Leone,1957,2295678,Africa,31.57,1004.484437 +Sierra Leone,1962,2467895,Africa,32.767,1116.639877 +Sierra Leone,1967,2662190,Africa,34.113,1206.043465 +Sierra Leone,1972,2879013,Africa,35.4,1353.759762 +Sierra Leone,1977,3140897,Africa,36.788,1348.285159 +Sierra Leone,1982,3464522,Africa,38.445,1465.010784 +Sierra Leone,1987,3868905,Africa,40.006,1294.447788 +Sierra Leone,1992,4260884,Africa,38.333,1068.696278 +Sierra Leone,1997,4578212,Africa,39.897,574.6481576 +Sierra Leone,2002,5359092,Africa,41.012,699.489713 +Sierra Leone,2007,6144562,Africa,42.568,862.5407561 +Singapore,1952,1127000,Asia,60.396,2315.138227 +Singapore,1957,1445929,Asia,63.179,2843.104409 +Singapore,1962,1750200,Asia,65.798,3674.735572 +Singapore,1967,1977600,Asia,67.946,4977.41854 +Singapore,1972,2152400,Asia,69.521,8597.756202 +Singapore,1977,2325300,Asia,70.795,11210.08948 +Singapore,1982,2651869,Asia,71.76,15169.16112 +Singapore,1987,2794552,Asia,73.56,18861.53081 +Singapore,1992,3235865,Asia,75.788,24769.8912 +Singapore,1997,3802309,Asia,77.158,33519.4766 +Singapore,2002,4197776,Asia,78.77,36023.1054 +Singapore,2007,4553009,Asia,79.972,47143.17964 +Slovak Republic,1952,3558137,Europe,64.36,5074.659104 +Slovak Republic,1957,3844277,Europe,67.45,6093.26298 +Slovak Republic,1962,4237384,Europe,70.33,7481.107598 +Slovak Republic,1967,4442238,Europe,70.98,8412.902397 +Slovak Republic,1972,4593433,Europe,70.35,9674.167626 +Slovak Republic,1977,4827803,Europe,70.45,10922.66404 +Slovak Republic,1982,5048043,Europe,70.8,11348.54585 +Slovak Republic,1987,5199318,Europe,71.08,12037.26758 +Slovak Republic,1992,5302888,Europe,71.38,9498.467723 +Slovak Republic,1997,5383010,Europe,72.71,12126.23065 +Slovak Republic,2002,5410052,Europe,73.8,13638.77837 +Slovak Republic,2007,5447502,Europe,74.663,18678.31435 +Slovenia,1952,1489518,Europe,65.57,4215.041741 +Slovenia,1957,1533070,Europe,67.85,5862.276629 +Slovenia,1962,1582962,Europe,69.15,7402.303395 +Slovenia,1967,1646912,Europe,69.18,9405.489397 +Slovenia,1972,1694510,Europe,69.82,12383.4862 +Slovenia,1977,1746919,Europe,70.97,15277.03017 +Slovenia,1982,1861252,Europe,71.063,17866.72175 +Slovenia,1987,1945870,Europe,72.25,18678.53492 +Slovenia,1992,1999210,Europe,73.64,14214.71681 +Slovenia,1997,2011612,Europe,75.13,17161.10735 +Slovenia,2002,2011497,Europe,76.66,20660.01936 +Slovenia,2007,2009245,Europe,77.926,25768.25759 +Somalia,1952,2526994,Africa,32.978,1135.749842 +Somalia,1957,2780415,Africa,34.977,1258.147413 +Somalia,1962,3080153,Africa,36.981,1369.488336 +Somalia,1967,3428839,Africa,38.977,1284.73318 +Somalia,1972,3840161,Africa,40.973,1254.576127 +Somalia,1977,4353666,Africa,41.974,1450.992513 +Somalia,1982,5828892,Africa,42.955,1176.807031 +Somalia,1987,6921858,Africa,44.501,1093.244963 +Somalia,1992,6099799,Africa,39.658,926.9602964 +Somalia,1997,6633514,Africa,43.795,930.5964284 +Somalia,2002,7753310,Africa,45.936,882.0818218 +Somalia,2007,9118773,Africa,48.159,926.1410683 +South Africa,1952,14264935,Africa,45.009,4725.295531 +South Africa,1957,16151549,Africa,47.985,5487.104219 +South Africa,1962,18356657,Africa,49.951,5768.729717 +South Africa,1967,20997321,Africa,51.927,7114.477971 +South Africa,1972,23935810,Africa,53.696,7765.962636 +South Africa,1977,27129932,Africa,55.527,8028.651439 +South Africa,1982,31140029,Africa,58.161,8568.266228 +South Africa,1987,35933379,Africa,60.834,7825.823398 +South Africa,1992,39964159,Africa,61.888,7225.069258 +South Africa,1997,42835005,Africa,60.236,7479.188244 +South Africa,2002,44433622,Africa,53.365,7710.946444 +South Africa,2007,43997828,Africa,49.339,9269.657808 +Spain,1952,28549870,Europe,64.94,3834.034742 +Spain,1957,29841614,Europe,66.66,4564.80241 +Spain,1962,31158061,Europe,69.69,5693.843879 +Spain,1967,32850275,Europe,71.44,7993.512294 +Spain,1972,34513161,Europe,73.06,10638.75131 +Spain,1977,36439000,Europe,74.39,13236.92117 +Spain,1982,37983310,Europe,76.3,13926.16997 +Spain,1987,38880702,Europe,76.9,15764.98313 +Spain,1992,39549438,Europe,77.57,18603.06452 +Spain,1997,39855442,Europe,78.77,20445.29896 +Spain,2002,40152517,Europe,79.78,24835.47166 +Spain,2007,40448191,Europe,80.941,28821.0637 +Sri Lanka,1952,7982342,Asia,57.593,1083.53203 +Sri Lanka,1957,9128546,Asia,61.456,1072.546602 +Sri Lanka,1962,10421936,Asia,62.192,1074.47196 +Sri Lanka,1967,11737396,Asia,64.266,1135.514326 +Sri Lanka,1972,13016733,Asia,65.042,1213.39553 +Sri Lanka,1977,14116836,Asia,65.949,1348.775651 +Sri Lanka,1982,15410151,Asia,68.757,1648.079789 +Sri Lanka,1987,16495304,Asia,69.011,1876.766827 +Sri Lanka,1992,17587060,Asia,70.379,2153.739222 +Sri Lanka,1997,18698655,Asia,70.457,2664.477257 +Sri Lanka,2002,19576783,Asia,70.815,3015.378833 +Sri Lanka,2007,20378239,Asia,72.396,3970.095407 +Sudan,1952,8504667,Africa,38.635,1615.991129 +Sudan,1957,9753392,Africa,39.624,1770.337074 +Sudan,1962,11183227,Africa,40.87,1959.593767 +Sudan,1967,12716129,Africa,42.858,1687.997641 +Sudan,1972,14597019,Africa,45.083,1659.652775 +Sudan,1977,17104986,Africa,47.8,2202.988423 +Sudan,1982,20367053,Africa,50.338,1895.544073 +Sudan,1987,24725960,Africa,51.744,1507.819159 +Sudan,1992,28227588,Africa,53.556,1492.197043 +Sudan,1997,32160729,Africa,55.373,1632.210764 +Sudan,2002,37090298,Africa,56.369,1993.398314 +Sudan,2007,42292929,Africa,58.556,2602.394995 +Swaziland,1952,290243,Africa,41.407,1148.376626 +Swaziland,1957,326741,Africa,43.424,1244.708364 +Swaziland,1962,370006,Africa,44.992,1856.182125 +Swaziland,1967,420690,Africa,46.633,2613.101665 +Swaziland,1972,480105,Africa,49.552,3364.836625 +Swaziland,1977,551425,Africa,52.537,3781.410618 +Swaziland,1982,649901,Africa,55.561,3895.384018 +Swaziland,1987,779348,Africa,57.678,3984.839812 +Swaziland,1992,962344,Africa,58.474,3553.0224 +Swaziland,1997,1054486,Africa,54.289,3876.76846 +Swaziland,2002,1130269,Africa,43.869,4128.116943 +Swaziland,2007,1133066,Africa,39.613,4513.480643 +Sweden,1952,7124673,Europe,71.86,8527.844662 +Sweden,1957,7363802,Europe,72.49,9911.878226 +Sweden,1962,7561588,Europe,73.37,12329.44192 +Sweden,1967,7867931,Europe,74.16,15258.29697 +Sweden,1972,8122293,Europe,74.72,17832.02464 +Sweden,1977,8251648,Europe,75.44,18855.72521 +Sweden,1982,8325260,Europe,76.42,20667.38125 +Sweden,1987,8421403,Europe,77.19,23586.92927 +Sweden,1992,8718867,Europe,78.16,23880.01683 +Sweden,1997,8897619,Europe,79.39,25266.59499 +Sweden,2002,8954175,Europe,80.04,29341.63093 +Sweden,2007,9031088,Europe,80.884,33859.74835 +Switzerland,1952,4815000,Europe,69.62,14734.23275 +Switzerland,1957,5126000,Europe,70.56,17909.48973 +Switzerland,1962,5666000,Europe,71.32,20431.0927 +Switzerland,1967,6063000,Europe,72.77,22966.14432 +Switzerland,1972,6401400,Europe,73.78,27195.11304 +Switzerland,1977,6316424,Europe,75.39,26982.29052 +Switzerland,1982,6468126,Europe,76.21,28397.71512 +Switzerland,1987,6649942,Europe,77.41,30281.70459 +Switzerland,1992,6995447,Europe,78.03,31871.5303 +Switzerland,1997,7193761,Europe,79.37,32135.32301 +Switzerland,2002,7361757,Europe,80.62,34480.95771 +Switzerland,2007,7554661,Europe,81.701,37506.41907 +Syria,1952,3661549,Asia,45.883,1643.485354 +Syria,1957,4149908,Asia,48.284,2117.234893 +Syria,1962,4834621,Asia,50.305,2193.037133 +Syria,1967,5680812,Asia,53.655,1881.923632 +Syria,1972,6701172,Asia,57.296,2571.423014 +Syria,1977,7932503,Asia,61.195,3195.484582 +Syria,1982,9410494,Asia,64.59,3761.837715 +Syria,1987,11242847,Asia,66.974,3116.774285 +Syria,1992,13219062,Asia,69.249,3340.542768 +Syria,1997,15081016,Asia,71.527,4014.238972 +Syria,2002,17155814,Asia,73.053,4090.925331 +Syria,2007,19314747,Asia,74.143,4184.548089 +Taiwan,1952,8550362,Asia,58.5,1206.947913 +Taiwan,1957,10164215,Asia,62.4,1507.86129 +Taiwan,1962,11918938,Asia,65.2,1822.879028 +Taiwan,1967,13648692,Asia,67.5,2643.858681 +Taiwan,1972,15226039,Asia,69.39,4062.523897 +Taiwan,1977,16785196,Asia,70.59,5596.519826 +Taiwan,1982,18501390,Asia,72.16,7426.354774 +Taiwan,1987,19757799,Asia,73.4,11054.56175 +Taiwan,1992,20686918,Asia,74.26,15215.6579 +Taiwan,1997,21628605,Asia,75.25,20206.82098 +Taiwan,2002,22454239,Asia,76.99,23235.42329 +Taiwan,2007,23174294,Asia,78.4,28718.27684 +Tanzania,1952,8322925,Africa,41.215,716.6500721 +Tanzania,1957,9452826,Africa,42.974,698.5356073 +Tanzania,1962,10863958,Africa,44.246,722.0038073 +Tanzania,1967,12607312,Africa,45.757,848.2186575 +Tanzania,1972,14706593,Africa,47.62,915.9850592 +Tanzania,1977,17129565,Africa,49.919,962.4922932 +Tanzania,1982,19844382,Africa,50.608,874.2426069 +Tanzania,1987,23040630,Africa,51.535,831.8220794 +Tanzania,1992,26605473,Africa,50.44,825.682454 +Tanzania,1997,30686889,Africa,48.466,789.1862231 +Tanzania,2002,34593779,Africa,49.651,899.0742111 +Tanzania,2007,38139640,Africa,52.517,1107.482182 +Thailand,1952,21289402,Asia,50.848,757.7974177 +Thailand,1957,25041917,Asia,53.63,793.5774148 +Thailand,1962,29263397,Asia,56.061,1002.199172 +Thailand,1967,34024249,Asia,58.285,1295.46066 +Thailand,1972,39276153,Asia,60.405,1524.358936 +Thailand,1977,44148285,Asia,62.494,1961.224635 +Thailand,1982,48827160,Asia,64.597,2393.219781 +Thailand,1987,52910342,Asia,66.084,2982.653773 +Thailand,1992,56667095,Asia,67.298,4616.896545 +Thailand,1997,60216677,Asia,67.521,5852.625497 +Thailand,2002,62806748,Asia,68.564,5913.187529 +Thailand,2007,65068149,Asia,70.616,7458.396327 +Togo,1952,1219113,Africa,38.596,859.8086567 +Togo,1957,1357445,Africa,41.208,925.9083202 +Togo,1962,1528098,Africa,43.922,1067.53481 +Togo,1967,1735550,Africa,46.769,1477.59676 +Togo,1972,2056351,Africa,49.759,1649.660188 +Togo,1977,2308582,Africa,52.887,1532.776998 +Togo,1982,2644765,Africa,55.471,1344.577953 +Togo,1987,3154264,Africa,56.941,1202.201361 +Togo,1992,3747553,Africa,58.061,1034.298904 +Togo,1997,4320890,Africa,58.39,982.2869243 +Togo,2002,4977378,Africa,57.561,886.2205765 +Togo,2007,5701579,Africa,58.42,882.9699438 +Trinidad and Tobago,1952,662850,Americas,59.1,3023.271928 +Trinidad and Tobago,1957,764900,Americas,61.8,4100.3934 +Trinidad and Tobago,1962,887498,Americas,64.9,4997.523971 +Trinidad and Tobago,1967,960155,Americas,65.4,5621.368472 +Trinidad and Tobago,1972,975199,Americas,65.9,6619.551419 +Trinidad and Tobago,1977,1039009,Americas,68.3,7899.554209 +Trinidad and Tobago,1982,1116479,Americas,68.832,9119.528607 +Trinidad and Tobago,1987,1191336,Americas,69.582,7388.597823 +Trinidad and Tobago,1992,1183669,Americas,69.862,7370.990932 +Trinidad and Tobago,1997,1138101,Americas,69.465,8792.573126 +Trinidad and Tobago,2002,1101832,Americas,68.976,11460.60023 +Trinidad and Tobago,2007,1056608,Americas,69.819,18008.50924 +Tunisia,1952,3647735,Africa,44.6,1468.475631 +Tunisia,1957,3950849,Africa,47.1,1395.232468 +Tunisia,1962,4286552,Africa,49.579,1660.30321 +Tunisia,1967,4786986,Africa,52.053,1932.360167 +Tunisia,1972,5303507,Africa,55.602,2753.285994 +Tunisia,1977,6005061,Africa,59.837,3120.876811 +Tunisia,1982,6734098,Africa,64.048,3560.233174 +Tunisia,1987,7724976,Africa,66.894,3810.419296 +Tunisia,1992,8523077,Africa,70.001,4332.720164 +Tunisia,1997,9231669,Africa,71.973,4876.798614 +Tunisia,2002,9770575,Africa,73.042,5722.895655 +Tunisia,2007,10276158,Africa,73.923,7092.923025 +Turkey,1952,22235677,Europe,43.585,1969.10098 +Turkey,1957,25670939,Europe,48.079,2218.754257 +Turkey,1962,29788695,Europe,52.098,2322.869908 +Turkey,1967,33411317,Europe,54.336,2826.356387 +Turkey,1972,37492953,Europe,57.005,3450.69638 +Turkey,1977,42404033,Europe,59.507,4269.122326 +Turkey,1982,47328791,Europe,61.036,4241.356344 +Turkey,1987,52881328,Europe,63.108,5089.043686 +Turkey,1992,58179144,Europe,66.146,5678.348271 +Turkey,1997,63047647,Europe,68.835,6601.429915 +Turkey,2002,67308928,Europe,70.845,6508.085718 +Turkey,2007,71158647,Europe,71.777,8458.276384 +Uganda,1952,5824797,Africa,39.978,734.753484 +Uganda,1957,6675501,Africa,42.571,774.3710692 +Uganda,1962,7688797,Africa,45.344,767.2717398 +Uganda,1967,8900294,Africa,48.051,908.9185217 +Uganda,1972,10190285,Africa,51.016,950.735869 +Uganda,1977,11457758,Africa,50.35,843.7331372 +Uganda,1982,12939400,Africa,49.849,682.2662268 +Uganda,1987,15283050,Africa,51.509,617.7244065 +Uganda,1992,18252190,Africa,48.825,644.1707969 +Uganda,1997,21210254,Africa,44.578,816.559081 +Uganda,2002,24739869,Africa,47.813,927.7210018 +Uganda,2007,29170398,Africa,51.542,1056.380121 +United Kingdom,1952,50430000,Europe,69.18,9979.508487 +United Kingdom,1957,51430000,Europe,70.42,11283.17795 +United Kingdom,1962,53292000,Europe,70.76,12477.17707 +United Kingdom,1967,54959000,Europe,71.36,14142.85089 +United Kingdom,1972,56079000,Europe,72.01,15895.11641 +United Kingdom,1977,56179000,Europe,72.76,17428.74846 +United Kingdom,1982,56339704,Europe,74.04,18232.42452 +United Kingdom,1987,56981620,Europe,75.007,21664.78767 +United Kingdom,1992,57866349,Europe,76.42,22705.09254 +United Kingdom,1997,58808266,Europe,77.218,26074.53136 +United Kingdom,2002,59912431,Europe,78.471,29478.99919 +United Kingdom,2007,60776238,Europe,79.425,33203.26128 +United States,1952,157553000,Americas,68.44,13990.48208 +United States,1957,171984000,Americas,69.49,14847.12712 +United States,1962,186538000,Americas,70.21,16173.14586 +United States,1967,198712000,Americas,70.76,19530.36557 +United States,1972,209896000,Americas,71.34,21806.03594 +United States,1977,220239000,Americas,73.38,24072.63213 +United States,1982,232187835,Americas,74.65,25009.55914 +United States,1987,242803533,Americas,75.02,29884.35041 +United States,1992,256894189,Americas,76.09,32003.93224 +United States,1997,272911760,Americas,76.81,35767.43303 +United States,2002,287675526,Americas,77.31,39097.09955 +United States,2007,301139947,Americas,78.242,42951.65309 +Uruguay,1952,2252965,Americas,66.071,5716.766744 +Uruguay,1957,2424959,Americas,67.044,6150.772969 +Uruguay,1962,2598466,Americas,68.253,5603.357717 +Uruguay,1967,2748579,Americas,68.468,5444.61962 +Uruguay,1972,2829526,Americas,68.673,5703.408898 +Uruguay,1977,2873520,Americas,69.481,6504.339663 +Uruguay,1982,2953997,Americas,70.805,6920.223051 +Uruguay,1987,3045153,Americas,71.918,7452.398969 +Uruguay,1992,3149262,Americas,72.752,8137.004775 +Uruguay,1997,3262838,Americas,74.223,9230.240708 +Uruguay,2002,3363085,Americas,75.307,7727.002004 +Uruguay,2007,3447496,Americas,76.384,10611.46299 +Venezuela,1952,5439568,Americas,55.088,7689.799761 +Venezuela,1957,6702668,Americas,57.907,9802.466526 +Venezuela,1962,8143375,Americas,60.77,8422.974165 +Venezuela,1967,9709552,Americas,63.479,9541.474188 +Venezuela,1972,11515649,Americas,65.712,10505.25966 +Venezuela,1977,13503563,Americas,67.456,13143.95095 +Venezuela,1982,15620766,Americas,68.557,11152.41011 +Venezuela,1987,17910182,Americas,70.19,9883.584648 +Venezuela,1992,20265563,Americas,71.15,10733.92631 +Venezuela,1997,22374398,Americas,72.146,10165.49518 +Venezuela,2002,24287670,Americas,72.766,8605.047831 +Venezuela,2007,26084662,Americas,73.747,11415.80569 +Vietnam,1952,26246839,Asia,40.412,605.0664917 +Vietnam,1957,28998543,Asia,42.887,676.2854478 +Vietnam,1962,33796140,Asia,45.363,772.0491602 +Vietnam,1967,39463910,Asia,47.838,637.1232887 +Vietnam,1972,44655014,Asia,50.254,699.5016441 +Vietnam,1977,50533506,Asia,55.764,713.5371196 +Vietnam,1982,56142181,Asia,58.816,707.2357863 +Vietnam,1987,62826491,Asia,62.82,820.7994449 +Vietnam,1992,69940728,Asia,67.662,989.0231487 +Vietnam,1997,76048996,Asia,70.672,1385.896769 +Vietnam,2002,80908147,Asia,73.017,1764.456677 +Vietnam,2007,85262356,Asia,74.249,2441.576404 +West Bank and Gaza,1952,1030585,Asia,43.16,1515.592329 +West Bank and Gaza,1957,1070439,Asia,45.671,1827.067742 +West Bank and Gaza,1962,1133134,Asia,48.127,2198.956312 +West Bank and Gaza,1967,1142636,Asia,51.631,2649.715007 +West Bank and Gaza,1972,1089572,Asia,56.532,3133.409277 +West Bank and Gaza,1977,1261091,Asia,60.765,3682.831494 +West Bank and Gaza,1982,1425876,Asia,64.406,4336.032082 +West Bank and Gaza,1987,1691210,Asia,67.046,5107.197384 +West Bank and Gaza,1992,2104779,Asia,69.718,6017.654756 +West Bank and Gaza,1997,2826046,Asia,71.096,7110.667619 +West Bank and Gaza,2002,3389578,Asia,72.37,4515.487575 +West Bank and Gaza,2007,4018332,Asia,73.422,3025.349798 +Yemen Rep.,1952,4963829,Asia,32.548,781.7175761 +Yemen Rep.,1957,5498090,Asia,33.97,804.8304547 +Yemen Rep.,1962,6120081,Asia,35.18,825.6232006 +Yemen Rep.,1967,6740785,Asia,36.984,862.4421463 +Yemen Rep.,1972,7407075,Asia,39.848,1265.047031 +Yemen Rep.,1977,8403990,Asia,44.175,1829.765177 +Yemen Rep.,1982,9657618,Asia,49.113,1977.55701 +Yemen Rep.,1987,11219340,Asia,52.922,1971.741538 +Yemen Rep.,1992,13367997,Asia,55.599,1879.496673 +Yemen Rep.,1997,15826497,Asia,58.02,2117.484526 +Yemen Rep.,2002,18701257,Asia,60.308,2234.820827 +Yemen Rep.,2007,22211743,Asia,62.698,2280.769906 +Zambia,1952,2672000,Africa,42.038,1147.388831 +Zambia,1957,3016000,Africa,44.077,1311.956766 +Zambia,1962,3421000,Africa,46.023,1452.725766 +Zambia,1967,3900000,Africa,47.768,1777.077318 +Zambia,1972,4506497,Africa,50.107,1773.498265 +Zambia,1977,5216550,Africa,51.386,1588.688299 +Zambia,1982,6100407,Africa,51.821,1408.678565 +Zambia,1987,7272406,Africa,50.821,1213.315116 +Zambia,1992,8381163,Africa,46.1,1210.884633 +Zambia,1997,9417789,Africa,40.238,1071.353818 +Zambia,2002,10595811,Africa,39.193,1071.613938 +Zambia,2007,11746035,Africa,42.384,1271.211593 +Zimbabwe,1952,3080907,Africa,48.451,406.8841148 +Zimbabwe,1957,3646340,Africa,50.469,518.7642681 +Zimbabwe,1962,4277736,Africa,52.358,527.2721818 +Zimbabwe,1967,4995432,Africa,53.995,569.7950712 +Zimbabwe,1972,5861135,Africa,55.635,799.3621758 +Zimbabwe,1977,6642107,Africa,57.674,685.5876821 +Zimbabwe,1982,7636524,Africa,60.363,788.8550411 +Zimbabwe,1987,9216418,Africa,62.351,706.1573059 +Zimbabwe,1992,10704340,Africa,60.377,693.4207856 +Zimbabwe,1997,11404948,Africa,46.809,792.4499603 +Zimbabwe,2002,11926563,Africa,39.989,672.0386227 +Zimbabwe,2007,12311143,Africa,43.487,469.7092981 diff --git a/data/gapminder_wide.csv b/data/gapminder_wide.csv new file mode 100644 index 000000000..028508a5a --- /dev/null +++ b/data/gapminder_wide.csv @@ -0,0 +1,143 @@ +"continent","country","gdpPercap_1952","gdpPercap_1957","gdpPercap_1962","gdpPercap_1967","gdpPercap_1972","gdpPercap_1977","gdpPercap_1982","gdpPercap_1987","gdpPercap_1992","gdpPercap_1997","gdpPercap_2002","gdpPercap_2007","lifeExp_1952","lifeExp_1957","lifeExp_1962","lifeExp_1967","lifeExp_1972","lifeExp_1977","lifeExp_1982","lifeExp_1987","lifeExp_1992","lifeExp_1997","lifeExp_2002","lifeExp_2007","pop_1952","pop_1957","pop_1962","pop_1967","pop_1972","pop_1977","pop_1982","pop_1987","pop_1992","pop_1997","pop_2002","pop_2007" +"Africa","Algeria",2449.008185,3013.976023,2550.81688,3246.991771,4182.663766,4910.416756,5745.160213,5681.358539,5023.216647,4797.295051,5288.040382,6223.367465,43.077,45.685,48.303,51.407,54.518,58.014,61.368,65.799,67.744,69.152,70.994,72.301,9279525,10270856,11000948,12760499,14760787,17152804,20033753,23254956,26298373,29072015,31287142,33333216 +"Africa","Angola",3520.610273,3827.940465,4269.276742,5522.776375,5473.288005,3008.647355,2756.953672,2430.208311,2627.845685,2277.140884,2773.287312,4797.231267,30.015,31.999,34,35.985,37.928,39.483,39.942,39.906,40.647,40.963,41.003,42.731,4232095,4561361,4826015,5247469,5894858,6162675,7016384,7874230,8735988,9875024,10866106,12420476 +"Africa","Benin",1062.7522,959.6010805,949.4990641,1035.831411,1085.796879,1029.161251,1277.897616,1225.85601,1191.207681,1232.975292,1372.877931,1441.284873,38.223,40.358,42.618,44.885,47.014,49.19,50.904,52.337,53.919,54.777,54.406,56.728,1738315,1925173,2151895,2427334,2761407,3168267,3641603,4243788,4981671,6066080,7026113,8078314 +"Africa","Botswana",851.2411407,918.2325349,983.6539764,1214.709294,2263.611114,3214.857818,4551.14215,6205.88385,7954.111645,8647.142313,11003.60508,12569.85177,47.622,49.618,51.52,53.298,56.024,59.319,61.484,63.622,62.745,52.556,46.634,50.728,442308,474639,512764,553541,619351,781472,970347,1151184,1342614,1536536,1630347,1639131 +"Africa","Burkina Faso",543.2552413,617.1834648,722.5120206,794.8265597,854.7359763,743.3870368,807.1985855,912.0631417,931.7527731,946.2949618,1037.645221,1217.032994,31.975,34.906,37.814,40.697,43.591,46.137,48.122,49.557,50.26,50.324,50.65,52.295,4469979,4713416,4919632,5127935,5433886,5889574,6634596,7586551,8878303,10352843,12251209,14326203 +"Africa","Burundi",339.2964587,379.5646281,355.2032273,412.9775136,464.0995039,556.1032651,559.603231,621.8188189,631.6998778,463.1151478,446.4035126,430.0706916,39.031,40.533,42.045,43.548,44.057,45.91,47.471,48.211,44.736,45.326,47.36,49.58,2445618,2667518,2961915,3330989,3529983,3834415,4580410,5126023,5809236,6121610,7021078,8390505 +"Africa","Cameroon",1172.667655,1313.048099,1399.607441,1508.453148,1684.146528,1783.432873,2367.983282,2602.664206,1793.163278,1694.337469,1934.011449,2042.09524,38.523,40.428,42.643,44.799,47.049,49.355,52.961,54.985,54.314,52.199,49.856,50.43,5009067,5359923,5793633,6335506,7021028,7959865,9250831,10780667,12467171,14195809,15929988,17696293 +"Africa","Central African Republic",1071.310713,1190.844328,1193.068753,1136.056615,1070.013275,1109.374338,956.7529907,844.8763504,747.9055252,740.5063317,738.6906068,706.016537,35.463,37.464,39.475,41.478,43.457,46.775,48.295,50.485,49.396,46.066,43.308,44.741,1291695,1392284,1523478,1733638,1927260,2167533,2476971,2840009,3265124,3696513,4048013,4369038 +"Africa","Chad",1178.665927,1308.495577,1389.817618,1196.810565,1104.103987,1133.98495,797.9081006,952.386129,1058.0643,1004.961353,1156.18186,1704.063724,38.092,39.881,41.716,43.601,45.569,47.383,49.517,51.051,51.724,51.573,50.525,50.651,2682462,2894855,3150417,3495967,3899068,4388260,4875118,5498955,6429417,7562011,8835739,10238807 +"Africa","Comoros",1102.990936,1211.148548,1406.648278,1876.029643,1937.577675,1172.603047,1267.100083,1315.980812,1246.90737,1173.618235,1075.811558,986.1478792,40.715,42.46,44.467,46.472,48.944,50.939,52.933,54.926,57.939,60.66,62.974,65.152,153936,170928,191689,217378,250027,304739,348643,395114,454429,527982,614382,710960 +"Africa","Congo Dem. Rep.",780.5423257,905.8602303,896.3146335,861.5932424,904.8960685,795.757282,673.7478181,672.774812,457.7191807,312.188423,241.1658765,277.5518587,39.143,40.652,42.122,44.056,45.989,47.804,47.784,47.412,45.548,42.587,44.966,46.462,14100005,15577932,17486434,19941073,23007669,26480870,30646495,35481645,41672143,47798986,55379852,64606759 +"Africa","Congo Rep.",2125.621418,2315.056572,2464.783157,2677.939642,3213.152683,3259.178978,4879.507522,4201.194937,4016.239529,3484.164376,3484.06197,3632.557798,42.111,45.053,48.435,52.04,54.907,55.625,56.695,57.47,56.433,52.962,52.97,55.322,854885,940458,1047924,1179760,1340458,1536769,1774735,2064095,2409073,2800947,3328795,3800610 +"Africa","Cote d'Ivoire",1388.594732,1500.895925,1728.869428,2052.050473,2378.201111,2517.736547,2602.710169,2156.956069,1648.073791,1786.265407,1648.800823,1544.750112,40.477,42.469,44.93,47.35,49.801,52.374,53.983,54.655,52.044,47.991,46.832,48.328,2977019,3300000,3832408,4744870,6071696,7459574,9025951,10761098,12772596,14625967,16252726,18013409 +"Africa","Djibouti",2669.529475,2864.969076,3020.989263,3020.050513,3694.212352,3081.761022,2879.468067,2880.102568,2377.156192,1895.016984,1908.260867,2082.481567,34.812,37.328,39.693,42.074,44.366,46.519,48.812,50.04,51.604,53.157,53.373,54.791,63149,71851,89898,127617,178848,228694,305991,311025,384156,417908,447416,496374 +"Africa","Egypt",1418.822445,1458.915272,1693.335853,1814.880728,2024.008147,2785.493582,3503.729636,3885.46071,3794.755195,4173.181797,4754.604414,5581.180998,41.893,44.444,46.992,49.293,51.137,53.319,56.006,59.797,63.674,67.217,69.806,71.338,22223309,25009741,28173309,31681188,34807417,38783863,45681811,52799062,59402198,66134291,73312559,80264543 +"Africa","Equatorial Guinea",375.6431231,426.0964081,582.8419714,915.5960025,672.4122571,958.5668124,927.8253427,966.8968149,1132.055034,2814.480755,7703.4959,12154.08975,34.482,35.983,37.485,38.987,40.516,42.024,43.662,45.664,47.545,48.245,49.348,51.579,216964,232922,249220,259864,277603,192675,285483,341244,387838,439971,495627,551201 +"Africa","Eritrea",328.9405571,344.1618859,380.9958433,468.7949699,514.3242082,505.7538077,524.8758493,521.1341333,582.8585102,913.47079,765.3500015,641.3695236,35.928,38.047,40.158,42.189,44.142,44.535,43.89,46.453,49.991,53.378,55.24,58.04,1438760,1542611,1666618,1820319,2260187,2512642,2637297,2915959,3668440,4058319,4414865,4906585 +"Africa","Ethiopia",362.1462796,378.9041632,419.4564161,516.1186438,566.2439442,556.8083834,577.8607471,573.7413142,421.3534653,515.8894013,530.0535319,690.8055759,34.078,36.667,40.059,42.115,43.515,44.51,44.916,46.684,48.091,49.402,50.725,52.947,20860941,22815614,25145372,27860297,30770372,34617799,38111756,42999530,52088559,59861301,67946797,76511887 +"Africa","Gabon",4293.476475,4976.198099,6631.459222,8358.761987,11401.94841,21745.57328,15113.36194,11864.40844,13522.15752,14722.84188,12521.71392,13206.48452,37.003,38.999,40.489,44.598,48.69,52.79,56.564,60.19,61.366,60.461,56.761,56.735,420702,434904,455661,489004,537977,706367,753874,880397,985739,1126189,1299304,1454867 +"Africa","Gambia",485.2306591,520.9267111,599.650276,734.7829124,756.0868363,884.7552507,835.8096108,611.6588611,665.6244126,653.7301704,660.5855997,752.7497265,30,32.065,33.896,35.857,38.308,41.842,45.58,49.265,52.644,55.861,58.041,59.448,284320,323150,374020,439593,517101,608274,715523,848406,1025384,1235767,1457766,1688359 +"Africa","Ghana",911.2989371,1043.561537,1190.041118,1125.69716,1178.223708,993.2239571,876.032569,847.0061135,925.060154,1005.245812,1111.984578,1327.60891,43.149,44.779,46.452,48.072,49.875,51.756,53.744,55.729,57.501,58.556,58.453,60.022,5581001,6391288,7355248,8490213,9354120,10538093,11400338,14168101,16278738,18418288,20550751,22873338 +"Africa","Guinea",510.1964923,576.2670245,686.3736739,708.7595409,741.6662307,874.6858643,857.2503577,805.5724718,794.3484384,869.4497668,945.5835837,942.6542111,33.609,34.558,35.753,37.197,38.842,40.762,42.891,45.552,48.576,51.455,53.676,56.007,2664249,2876726,3140003,3451418,3811387,4227026,4710497,5650262,6990574,8048834,8807818,9947814 +"Africa","Guinea-Bissau",299.850319,431.7904566,522.0343725,715.5806402,820.2245876,764.7259628,838.1239671,736.4153921,745.5398706,796.6644681,575.7047176,579.231743,32.5,33.489,34.488,35.492,36.486,37.465,39.327,41.245,43.266,44.873,45.504,46.388,580653,601095,627820,601287,625361,745228,825987,927524,1050938,1193708,1332459,1472041 +"Africa","Kenya",853.540919,944.4383152,896.9663732,1056.736457,1222.359968,1267.613204,1348.225791,1361.936856,1341.921721,1360.485021,1287.514732,1463.249282,42.27,44.686,47.949,50.654,53.559,56.155,58.766,59.339,59.285,54.407,50.992,54.11,6464046,7454779,8678557,10191512,12044785,14500404,17661452,21198082,25020539,28263827,31386842,35610177 +"Africa","Lesotho",298.8462121,335.9971151,411.8006266,498.6390265,496.5815922,745.3695408,797.2631074,773.9932141,977.4862725,1186.147994,1275.184575,1569.331442,42.138,45.047,47.747,48.492,49.767,52.208,55.078,57.18,59.685,55.558,44.593,42.592,748747,813338,893143,996380,1116779,1251524,1411807,1599200,1803195,1982823,2046772,2012649 +"Africa","Liberia",575.5729961,620.9699901,634.1951625,713.6036483,803.0054535,640.3224383,572.1995694,506.1138573,636.6229191,609.1739508,531.4823679,414.5073415,38.48,39.486,40.502,41.536,42.614,43.764,44.852,46.027,40.802,42.221,43.753,45.678,863308,975950,1112796,1279406,1482628,1703617,1956875,2269414,1912974,2200725,2814651,3193942 +"Africa","Libya",2387.54806,3448.284395,6757.030816,18772.75169,21011.49721,21951.21176,17364.27538,11770.5898,9640.138501,9467.446056,9534.677467,12057.49928,42.723,45.289,47.808,50.227,52.773,57.442,62.155,66.234,68.755,71.555,72.737,73.952,1019729,1201578,1441863,1759224,2183877,2721783,3344074,3799845,4364501,4759670,5368585,6036914 +"Africa","Madagascar",1443.011715,1589.20275,1643.38711,1634.047282,1748.562982,1544.228586,1302.878658,1155.441948,1040.67619,986.2958956,894.6370822,1044.770126,36.681,38.865,40.848,42.881,44.851,46.881,48.969,49.35,52.214,54.978,57.286,59.443,4762912,5181679,5703324,6334556,7082430,8007166,9171477,10568642,12210395,14165114,16473477,19167654 +"Africa","Malawi",369.1650802,416.3698064,427.9010856,495.5147806,584.6219709,663.2236766,632.8039209,635.5173634,563.2000145,692.2758103,665.4231186,759.3499101,36.256,37.207,38.41,39.487,41.766,43.767,45.642,47.457,49.42,47.495,45.009,48.303,2917802,3221238,3628608,4147252,4730997,5637246,6502825,7824747,10014249,10419991,11824495,13327079 +"Africa","Mali",452.3369807,490.3821867,496.1743428,545.0098873,581.3688761,686.3952693,618.0140641,684.1715576,739.014375,790.2579846,951.4097518,1042.581557,33.685,35.307,36.936,38.487,39.977,41.714,43.916,46.364,48.388,49.903,51.818,54.467,3838168,4241884,4690372,5212416,5828158,6491649,6998256,7634008,8416215,9384984,10580176,12031795 +"Africa","Mauritania",743.1159097,846.1202613,1055.896036,1421.145193,1586.851781,1497.492223,1481.150189,1421.603576,1361.369784,1483.136136,1579.019543,1803.151496,40.543,42.338,44.248,46.289,48.437,50.852,53.599,56.145,58.333,60.43,62.247,64.164,1022556,1076852,1146757,1230542,1332786,1456688,1622136,1841240,2119465,2444741,2828858,3270065 +"Africa","Mauritius",1967.955707,2034.037981,2529.067487,2475.387562,2575.484158,3710.982963,3688.037739,4783.586903,6058.253846,7425.705295,9021.815894,10956.99112,50.986,58.089,60.246,61.557,62.944,64.93,66.711,68.74,69.745,70.736,71.954,72.801,516556,609816,701016,789309,851334,913025,992040,1042663,1096202,1149818,1200206,1250882 +"Africa","Morocco",1688.20357,1642.002314,1566.353493,1711.04477,1930.194975,2370.619976,2702.620356,2755.046991,2948.047252,2982.101858,3258.495584,3820.17523,42.873,45.423,47.924,50.335,52.862,55.73,59.65,62.677,65.393,67.66,69.615,71.164,9939217,11406350,13056604,14770296,16660670,18396941,20198730,22987397,25798239,28529501,31167783,33757175 +"Africa","Mozambique",468.5260381,495.5868333,556.6863539,566.6691539,724.9178037,502.3197334,462.2114149,389.8761846,410.8968239,472.3460771,633.6179466,823.6856205,31.286,33.779,36.161,38.113,40.328,42.495,42.795,42.861,44.284,46.344,44.026,42.082,6446316,7038035,7788944,8680909,9809596,11127868,12587223,12891952,13160731,16603334,18473780,19951656 +"Africa","Namibia",2423.780443,2621.448058,3173.215595,3793.694753,3746.080948,3876.485958,4191.100511,3693.731337,3804.537999,3899.52426,4072.324751,4811.060429,41.725,45.226,48.386,51.159,53.867,56.437,58.968,60.835,61.999,58.909,51.479,52.906,485831,548080,621392,706640,821782,977026,1099010,1278184,1554253,1774766,1972153,2055080 +"Africa","Niger",761.879376,835.5234025,997.7661127,1054.384891,954.2092363,808.8970728,909.7221354,668.3000228,581.182725,580.3052092,601.0745012,619.6768924,37.444,38.598,39.487,40.118,40.546,41.291,42.598,44.555,47.391,51.313,54.496,56.867,3379468,3692184,4076008,4534062,5060262,5682086,6437188,7332638,8392818,9666252,11140655,12894865 +"Africa","Nigeria",1077.281856,1100.592563,1150.927478,1014.514104,1698.388838,1981.951806,1576.97375,1385.029563,1619.848217,1624.941275,1615.286395,2013.977305,36.324,37.802,39.36,41.04,42.821,44.514,45.826,46.886,47.472,47.464,46.608,46.859,33119096,37173340,41871351,47287752,53740085,62209173,73039376,81551520,93364244,106207839,119901274,135031164 +"Africa","Reunion",2718.885295,2769.451844,3173.72334,4021.175739,5047.658563,4319.804067,5267.219353,5303.377488,6101.255823,6071.941411,6316.1652,7670.122558,52.724,55.09,57.666,60.542,64.274,67.064,69.885,71.913,73.615,74.772,75.744,76.442,257700,308700,358900,414024,461633,492095,517810,562035,622191,684810,743981,798094 +"Africa","Rwanda",493.3238752,540.2893983,597.4730727,510.9637142,590.5806638,670.0806011,881.5706467,847.991217,737.0685949,589.9445051,785.6537648,863.0884639,40,41.5,43,44.1,44.6,45,46.218,44.02,23.599,36.087,43.413,46.242,2534927,2822082,3051242,3451079,3992121,4657072,5507565,6349365,7290203,7212583,7852401,8860588 +"Africa","Sao Tome and Principe",879.5835855,860.7369026,1071.551119,1384.840593,1532.985254,1737.561657,1890.218117,1516.525457,1428.777814,1339.076036,1353.09239,1598.435089,46.471,48.945,51.893,54.425,56.48,58.55,60.351,61.728,62.742,63.306,64.337,65.528,60011,61325,65345,70787,76595,86796,98593,110812,125911,145608,170372,199579 +"Africa","Senegal",1450.356983,1567.653006,1654.988723,1612.404632,1597.712056,1561.769116,1518.479984,1441.72072,1367.899369,1392.368347,1519.635262,1712.472136,37.278,39.329,41.454,43.563,45.815,48.879,52.379,55.769,58.196,60.187,61.6,63.062,2755589,3054547,3430243,3965841,4588696,5260855,6147783,7171347,8307920,9535314,10870037,12267493 +"Africa","Sierra Leone",879.7877358,1004.484437,1116.639877,1206.043465,1353.759762,1348.285159,1465.010784,1294.447788,1068.696278,574.6481576,699.489713,862.5407561,30.331,31.57,32.767,34.113,35.4,36.788,38.445,40.006,38.333,39.897,41.012,42.568,2143249,2295678,2467895,2662190,2879013,3140897,3464522,3868905,4260884,4578212,5359092,6144562 +"Africa","Somalia",1135.749842,1258.147413,1369.488336,1284.73318,1254.576127,1450.992513,1176.807031,1093.244963,926.9602964,930.5964284,882.0818218,926.1410683,32.978,34.977,36.981,38.977,40.973,41.974,42.955,44.501,39.658,43.795,45.936,48.159,2526994,2780415,3080153,3428839,3840161,4353666,5828892,6921858,6099799,6633514,7753310,9118773 +"Africa","South Africa",4725.295531,5487.104219,5768.729717,7114.477971,7765.962636,8028.651439,8568.266228,7825.823398,7225.069258,7479.188244,7710.946444,9269.657808,45.009,47.985,49.951,51.927,53.696,55.527,58.161,60.834,61.888,60.236,53.365,49.339,14264935,16151549,18356657,20997321,23935810,27129932,31140029,35933379,39964159,42835005,44433622,43997828 +"Africa","Sudan",1615.991129,1770.337074,1959.593767,1687.997641,1659.652775,2202.988423,1895.544073,1507.819159,1492.197043,1632.210764,1993.398314,2602.394995,38.635,39.624,40.87,42.858,45.083,47.8,50.338,51.744,53.556,55.373,56.369,58.556,8504667,9753392,11183227,12716129,14597019,17104986,20367053,24725960,28227588,32160729,37090298,42292929 +"Africa","Swaziland",1148.376626,1244.708364,1856.182125,2613.101665,3364.836625,3781.410618,3895.384018,3984.839812,3553.0224,3876.76846,4128.116943,4513.480643,41.407,43.424,44.992,46.633,49.552,52.537,55.561,57.678,58.474,54.289,43.869,39.613,290243,326741,370006,420690,480105,551425,649901,779348,962344,1054486,1130269,1133066 +"Africa","Tanzania",716.6500721,698.5356073,722.0038073,848.2186575,915.9850592,962.4922932,874.2426069,831.8220794,825.682454,789.1862231,899.0742111,1107.482182,41.215,42.974,44.246,45.757,47.62,49.919,50.608,51.535,50.44,48.466,49.651,52.517,8322925,9452826,10863958,12607312,14706593,17129565,19844382,23040630,26605473,30686889,34593779,38139640 +"Africa","Togo",859.8086567,925.9083202,1067.53481,1477.59676,1649.660188,1532.776998,1344.577953,1202.201361,1034.298904,982.2869243,886.2205765,882.9699438,38.596,41.208,43.922,46.769,49.759,52.887,55.471,56.941,58.061,58.39,57.561,58.42,1219113,1357445,1528098,1735550,2056351,2308582,2644765,3154264,3747553,4320890,4977378,5701579 +"Africa","Tunisia",1468.475631,1395.232468,1660.30321,1932.360167,2753.285994,3120.876811,3560.233174,3810.419296,4332.720164,4876.798614,5722.895655,7092.923025,44.6,47.1,49.579,52.053,55.602,59.837,64.048,66.894,70.001,71.973,73.042,73.923,3647735,3950849,4286552,4786986,5303507,6005061,6734098,7724976,8523077,9231669,9770575,10276158 +"Africa","Uganda",734.753484,774.3710692,767.2717398,908.9185217,950.735869,843.7331372,682.2662268,617.7244065,644.1707969,816.559081,927.7210018,1056.380121,39.978,42.571,45.344,48.051,51.016,50.35,49.849,51.509,48.825,44.578,47.813,51.542,5824797,6675501,7688797,8900294,10190285,11457758,12939400,15283050,18252190,21210254,24739869,29170398 +"Africa","Zambia",1147.388831,1311.956766,1452.725766,1777.077318,1773.498265,1588.688299,1408.678565,1213.315116,1210.884633,1071.353818,1071.613938,1271.211593,42.038,44.077,46.023,47.768,50.107,51.386,51.821,50.821,46.1,40.238,39.193,42.384,2672000,3016000,3421000,3900000,4506497,5216550,6100407,7272406,8381163,9417789,10595811,11746035 +"Africa","Zimbabwe",406.8841148,518.7642681,527.2721818,569.7950712,799.3621758,685.5876821,788.8550411,706.1573059,693.4207856,792.4499603,672.0386227,469.7092981,48.451,50.469,52.358,53.995,55.635,57.674,60.363,62.351,60.377,46.809,39.989,43.487,3080907,3646340,4277736,4995432,5861135,6642107,7636524,9216418,10704340,11404948,11926563,12311143 +"Americas","Argentina",5911.315053,6856.856212,7133.166023,8052.953021,9443.038526,10079.02674,8997.897412,9139.671389,9308.41871,10967.28195,8797.640716,12779.37964,62.485,64.399,65.142,65.634,67.065,68.481,69.942,70.774,71.868,73.275,74.34,75.32,17876956,19610538,21283783,22934225,24779799,26983828,29341374,31620918,33958947,36203463,38331121,40301927 +"Americas","Bolivia",2677.326347,2127.686326,2180.972546,2586.886053,2980.331339,3548.097832,3156.510452,2753.69149,2961.699694,3326.143191,3413.26269,3822.137084,40.414,41.89,43.428,45.032,46.714,50.023,53.859,57.251,59.957,62.05,63.883,65.554,2883315,3211738,3593918,4040665,4565872,5079716,5642224,6156369,6893451,7693188,8445134,9119152 +"Americas","Brazil",2108.944355,2487.365989,3336.585802,3429.864357,4985.711467,6660.118654,7030.835878,7807.095818,6950.283021,7957.980824,8131.212843,9065.800825,50.917,53.285,55.665,57.632,59.504,61.489,63.336,65.205,67.057,69.388,71.006,72.39,56602560,65551171,76039390,88049823,100840058,114313951,128962939,142938076,155975974,168546719,179914212,190010647 +"Americas","Canada",11367.16112,12489.95006,13462.48555,16076.58803,18970.57086,22090.88306,22898.79214,26626.51503,26342.88426,28954.92589,33328.96507,36319.23501,68.75,69.96,71.3,72.13,72.88,74.21,75.76,76.86,77.95,78.61,79.77,80.653,14785584,17010154,18985849,20819767,22284500,23796400,25201900,26549700,28523502,30305843,31902268,33390141 +"Americas","Chile",3939.978789,4315.622723,4519.094331,5106.654313,5494.024437,4756.763836,5095.665738,5547.063754,7596.125964,10118.05318,10778.78385,13171.63885,54.745,56.074,57.924,60.523,63.441,67.052,70.565,72.492,74.126,75.816,77.86,78.553,6377619,7048426,7961258,8858908,9717524,10599793,11487112,12463354,13572994,14599929,15497046,16284741 +"Americas","Colombia",2144.115096,2323.805581,2492.351109,2678.729839,3264.660041,3815.80787,4397.575659,4903.2191,5444.648617,6117.361746,5755.259962,7006.580419,50.643,55.118,57.863,59.963,61.623,63.837,66.653,67.768,68.421,70.313,71.682,72.889,12350771,14485993,17009885,19764027,22542890,25094412,27764644,30964245,34202721,37657830,41008227,44227550 +"Americas","Costa Rica",2627.009471,2990.010802,3460.937025,4161.727834,5118.146939,5926.876967,5262.734751,5629.915318,6160.416317,6677.045314,7723.447195,9645.06142,57.206,60.026,62.842,65.424,67.849,70.75,73.45,74.752,75.713,77.26,78.123,78.782,926317,1112300,1345187,1588717,1834796,2108457,2424367,2799811,3173216,3518107,3834934,4133884 +"Americas","Cuba",5586.53878,6092.174359,5180.75591,5690.268015,5305.445256,6380.494966,7316.918107,7532.924763,5592.843963,5431.990415,6340.646683,8948.102923,59.421,62.325,65.246,68.29,70.723,72.649,73.717,74.174,74.414,76.151,77.158,78.273,6007797,6640752,7254373,8139332,8831348,9537988,9789224,10239839,10723260,10983007,11226999,11416987 +"Americas","Dominican Republic",1397.717137,1544.402995,1662.137359,1653.723003,2189.874499,2681.9889,2861.092386,2899.842175,3044.214214,3614.101285,4563.808154,6025.374752,45.928,49.828,53.459,56.751,59.631,61.788,63.727,66.046,68.457,69.957,70.847,72.235,2491346,2923186,3453434,4049146,4671329,5302800,5968349,6655297,7351181,7992357,8650322,9319622 +"Americas","Ecuador",3522.110717,3780.546651,4086.114078,4579.074215,5280.99471,6679.62326,7213.791267,6481.776993,7103.702595,7429.455877,5773.044512,6873.262326,48.357,51.356,54.64,56.678,58.796,61.31,64.342,67.231,69.613,72.312,74.173,74.994,3548753,4058385,4681707,5432424,6298651,7278866,8365850,9545158,10748394,11911819,12921234,13755680 +"Americas","El Salvador",3048.3029,3421.523218,3776.803627,4358.595393,4520.246008,5138.922374,4098.344175,4140.442097,4444.2317,5154.825496,5351.568666,5728.353514,45.262,48.57,52.307,55.855,58.207,56.696,56.604,63.154,66.798,69.535,70.734,71.878,2042865,2355805,2747687,3232927,3790903,4282586,4474873,4842194,5274649,5783439,6353681,6939688 +"Americas","Guatemala",2428.237769,2617.155967,2750.364446,3242.531147,4031.408271,4879.992748,4820.49479,4246.485974,4439.45084,4684.313807,4858.347495,5186.050003,42.023,44.142,46.954,50.016,53.738,56.029,58.137,60.782,63.373,66.322,68.978,70.259,3146381,3640876,4208858,4690773,5149581,5703430,6395630,7326406,8486949,9803875,11178650,12572928 +"Americas","Haiti",1840.366939,1726.887882,1796.589032,1452.057666,1654.456946,1874.298931,2011.159549,1823.015995,1456.309517,1341.726931,1270.364932,1201.637154,37.579,40.696,43.59,46.243,48.042,49.923,51.461,53.636,55.089,56.671,58.137,60.916,3201488,3507701,3880130,4318137,4698301,4908554,5198399,5756203,6326682,6913545,7607651,8502814 +"Americas","Honduras",2194.926204,2220.487682,2291.156835,2538.269358,2529.842345,3203.208066,3121.760794,3023.096699,3081.694603,3160.454906,3099.72866,3548.330846,41.912,44.665,48.041,50.924,53.884,57.402,60.909,64.492,66.399,67.659,68.565,70.198,1517453,1770390,2090162,2500689,2965146,3055235,3669448,4372203,5077347,5867957,6677328,7483763 +"Americas","Jamaica",2898.530881,4756.525781,5246.107524,6124.703451,7433.889293,6650.195573,6068.05135,6351.237495,7404.923685,7121.924704,6994.774861,7320.880262,58.53,62.61,65.61,67.51,69,70.11,71.21,71.77,71.766,72.262,72.047,72.567,1426095,1535090,1665128,1861096,1997616,2156814,2298309,2326606,2378618,2531311,2664659,2780132 +"Americas","Mexico",3478.125529,4131.546641,4581.609385,5754.733883,6809.40669,7674.929108,9611.147541,8688.156003,9472.384295,9767.29753,10742.44053,11977.57496,50.789,55.19,58.299,60.11,62.361,65.032,67.405,69.498,71.455,73.67,74.902,76.195,30144317,35015548,41121485,47995559,55984294,63759976,71640904,80122492,88111030,95895146,102479927,108700891 +"Americas","Nicaragua",3112.363948,3457.415947,3634.364406,4643.393534,4688.593267,5486.371089,3470.338156,2955.984375,2170.151724,2253.023004,2474.548819,2749.320965,42.314,45.432,48.632,51.884,55.151,57.47,59.298,62.008,65.843,68.426,70.836,72.899,1165790,1358828,1590597,1865490,2182908,2554598,2979423,3344353,4017939,4609572,5146848,5675356 +"Americas","Panama",2480.380334,2961.800905,3536.540301,4421.009084,5364.249663,5351.912144,7009.601598,7034.779161,6618.74305,7113.692252,7356.031934,9809.185636,55.191,59.201,61.817,64.071,66.216,68.681,70.472,71.523,72.462,73.738,74.712,75.537,940080,1063506,1215725,1405486,1616384,1839782,2036305,2253639,2484997,2734531,2990875,3242173 +"Americas","Paraguay",1952.308701,2046.154706,2148.027146,2299.376311,2523.337977,3248.373311,4258.503604,3998.875695,4196.411078,4247.400261,3783.674243,4172.838464,62.649,63.196,64.361,64.951,65.815,66.353,66.874,67.378,68.225,69.4,70.755,71.752,1555876,1770902,2009813,2287985,2614104,2984494,3366439,3886512,4483945,5154123,5884491,6667147 +"Americas","Peru",3758.523437,4245.256698,4957.037982,5788.09333,5937.827283,6281.290855,6434.501797,6360.943444,4446.380924,5838.347657,5909.020073,7408.905561,43.902,46.263,49.096,51.445,55.448,58.447,61.406,64.134,66.458,68.386,69.906,71.421,8025700,9146100,10516500,12132200,13954700,15990099,18125129,20195924,22430449,24748122,26769436,28674757 +"Americas","Puerto Rico",3081.959785,3907.156189,5108.34463,6929.277714,9123.041742,9770.524921,10330.98915,12281.34191,14641.58711,16999.4333,18855.60618,19328.70901,64.28,68.54,69.62,71.1,72.16,73.44,73.75,74.63,73.911,74.917,77.778,78.746,2227000,2260000,2448046,2648961,2847132,3080828,3279001,3444468,3585176,3759430,3859606,3942491 +"Americas","Trinidad and Tobago",3023.271928,4100.3934,4997.523971,5621.368472,6619.551419,7899.554209,9119.528607,7388.597823,7370.990932,8792.573126,11460.60023,18008.50924,59.1,61.8,64.9,65.4,65.9,68.3,68.832,69.582,69.862,69.465,68.976,69.819,662850,764900,887498,960155,975199,1039009,1116479,1191336,1183669,1138101,1101832,1056608 +"Americas","United States",13990.48208,14847.12712,16173.14586,19530.36557,21806.03594,24072.63213,25009.55914,29884.35041,32003.93224,35767.43303,39097.09955,42951.65309,68.44,69.49,70.21,70.76,71.34,73.38,74.65,75.02,76.09,76.81,77.31,78.242,157553000,171984000,186538000,198712000,209896000,220239000,232187835,242803533,256894189,272911760,287675526,301139947 +"Americas","Uruguay",5716.766744,6150.772969,5603.357717,5444.61962,5703.408898,6504.339663,6920.223051,7452.398969,8137.004775,9230.240708,7727.002004,10611.46299,66.071,67.044,68.253,68.468,68.673,69.481,70.805,71.918,72.752,74.223,75.307,76.384,2252965,2424959,2598466,2748579,2829526,2873520,2953997,3045153,3149262,3262838,3363085,3447496 +"Americas","Venezuela",7689.799761,9802.466526,8422.974165,9541.474188,10505.25966,13143.95095,11152.41011,9883.584648,10733.92631,10165.49518,8605.047831,11415.80569,55.088,57.907,60.77,63.479,65.712,67.456,68.557,70.19,71.15,72.146,72.766,73.747,5439568,6702668,8143375,9709552,11515649,13503563,15620766,17910182,20265563,22374398,24287670,26084662 +"Asia","Afghanistan",779.4453145,820.8530296,853.10071,836.1971382,739.9811058,786.11336,978.0114388,852.3959448,649.3413952,635.341351,726.7340548,974.5803384,28.801,30.332,31.997,34.02,36.088,38.438,39.854,40.822,41.674,41.763,42.129,43.828,8425333,9240934,10267083,11537966,13079460,14880372,12881816,13867957,16317921,22227415,25268405,31889923 +"Asia","Bahrain",9867.084765,11635.79945,12753.27514,14804.6727,18268.65839,19340.10196,19211.14731,18524.02406,19035.57917,20292.01679,23403.55927,29796.04834,50.939,53.832,56.923,59.923,63.3,65.593,69.052,70.75,72.601,73.925,74.795,75.635,120447,138655,171863,202182,230800,297410,377967,454612,529491,598561,656397,708573 +"Asia","Bangladesh",684.2441716,661.6374577,686.3415538,721.1860862,630.2336265,659.8772322,676.9818656,751.9794035,837.8101643,972.7700352,1136.39043,1391.253792,37.484,39.348,41.216,43.453,45.252,46.923,50.009,52.819,56.018,59.412,62.013,64.062,46886859,51365468,56839289,62821884,70759295,80428306,93074406,103764241,113704579,123315288,135656790,150448339 +"Asia","Cambodia",368.4692856,434.0383364,496.9136476,523.4323142,421.6240257,524.9721832,624.4754784,683.8955732,682.3031755,734.28517,896.2260153,1713.778686,39.417,41.366,43.415,45.415,40.317,31.22,50.957,53.914,55.803,56.534,56.752,59.723,4693836,5322536,6083619,6960067,7450606,6978607,7272485,8371791,10150094,11782962,12926707,14131858 +"Asia","China",400.448610699994,575.9870009,487.6740183,612.7056934,676.9000921,741.2374699,962.4213805,1378.904018,1655.784158,2289.234136,3119.280896,4959.114854,44,50.54896,44.50136,58.38112,63.11888,63.96736,65.525,67.274,68.69,70.426,72.028,72.961,556263527.999989,637408000,665770000,754550000,862030000,943455000,1000281000,1084035000,1164970000,1230075000,1280400000,1318683096 +"Asia","Hong Kong China",3054.421209,3629.076457,4692.648272,6197.962814,8315.928145,11186.14125,14560.53051,20038.47269,24757.60301,28377.63219,30209.01516,39724.97867,60.96,64.75,67.65,70,72,73.6,75.45,76.2,77.601,80,81.495,82.208,2125900,2736300,3305200,3722800,4115700,4583700,5264500,5584510,5829696,6495918,6762476,6980412 +"Asia","India",546.5657493,590.061996,658.3471509,700.7706107,724.032527,813.337323,855.7235377,976.5126756,1164.406809,1458.817442,1746.769454,2452.210407,37.373,40.249,43.605,47.193,50.651,54.208,56.596,58.553,60.223,61.765,62.879,64.698,3.72e+08,4.09e+08,4.54e+08,5.06e+08,5.67e+08,6.34e+08,7.08e+08,7.88e+08,8.72e+08,9.59e+08,1034172547,1110396331 +"Asia","Indonesia",749.6816546,858.9002707,849.2897701,762.4317721,1111.107907,1382.702056,1516.872988,1748.356961,2383.140898,3119.335603,2873.91287,3540.651564,37.468,39.918,42.518,45.964,49.203,52.702,56.159,60.137,62.681,66.041,68.588,70.65,82052000,90124000,99028000,109343000,121282000,136725000,153343000,169276000,184816000,199278000,211060000,223547000 +"Asia","Iran",3035.326002,3290.257643,4187.329802,5906.731805,9613.818607,11888.59508,7608.334602,6642.881371,7235.653188,8263.590301,9240.761975,11605.71449,44.869,47.181,49.325,52.469,55.234,57.702,59.62,63.04,65.742,68.042,69.451,70.964,17272000,19792000,22874000,26538000,30614000,35480679,43072751,51889696,60397973,63327987,66907826,69453570 +"Asia","Iraq",4129.766056,6229.333562,8341.737815,8931.459811,9576.037596,14688.23507,14517.90711,11643.57268,3745.640687,3076.239795,4390.717312,4471.061906,45.32,48.437,51.457,54.459,56.95,60.413,62.038,65.044,59.461,58.811,57.046,59.545,5441766,6248643,7240260,8519282,10061506,11882916,14173318,16543189,17861905,20775703,24001816,27499638 +"Asia","Israel",4086.522128,5385.278451,7105.630706,8393.741404,12786.93223,13306.61921,15367.0292,17122.47986,18051.52254,20896.60924,21905.59514,25523.2771,65.39,67.84,69.39,70.75,71.63,73.06,74.45,75.6,76.93,78.269,79.696,80.745,1620914,1944401,2310904,2693585,3095893,3495918,3858421,4203148,4936550,5531387,6029529,6426679 +"Asia","Japan",3216.956347,4317.694365,6576.649461,9847.788607,14778.78636,16610.37701,19384.10571,22375.94189,26824.89511,28816.58499,28604.5919,31656.06806,63.03,65.5,68.73,71.43,73.42,75.38,77.11,78.67,79.36,80.69,82,82.603,86459025,91563009,95831757,100825279,107188273,113872473,118454974,122091325,124329269,125956499,127065841,127467972 +"Asia","Jordan",1546.907807,1886.080591,2348.009158,2741.796252,2110.856309,2852.351568,4161.415959,4448.679912,3431.593647,3645.379572,3844.917194,4519.461171,43.158,45.669,48.126,51.629,56.528,61.134,63.739,65.869,68.015,69.772,71.263,72.535,607914,746559,933559,1255058,1613551,1937652,2347031,2820042,3867409,4526235,5307470,6053193 +"Asia","Korea Dem. Rep.",1088.277758,1571.134655,1621.693598,2143.540609,3701.621503,4106.301249,4106.525293,4106.492315,3726.063507,1690.756814,1646.758151,1593.06548,50.056,54.081,56.656,59.942,63.983,67.159,69.1,70.647,69.978,67.727,66.662,67.297,8865488,9411381,10917494,12617009,14781241,16325320,17647518,19067554,20711375,21585105,22215365,23301725 +"Asia","Korea Rep.",1030.592226,1487.593537,1536.344387,2029.228142,3030.87665,4657.22102,5622.942464,8533.088805,12104.27872,15993.52796,19233.98818,23348.13973,47.453,52.681,55.292,57.716,62.612,64.766,67.123,69.81,72.244,74.647,77.045,78.623,20947571,22611552,26420307,30131000,33505000,36436000,39326000,41622000,43805450,46173816,47969150,49044790 +"Asia","Kuwait",108382.3529,113523.1329,95458.11176,80894.88326,109347.867,59265.47714,31354.03573,28118.42998,34932.91959,40300.61996,35110.10566,47306.98978,55.565,58.033,60.47,64.624,67.712,69.343,71.309,74.174,75.19,76.156,76.904,77.588,160000,212846,358266,575003,841934,1140357,1497494,1891487,1418095,1765345,2111561,2505559 +"Asia","Lebanon",4834.804067,6089.786934,5714.560611,6006.983042,7486.384341,8659.696836,7640.519521,5377.091329,6890.806854,8754.96385,9313.93883,10461.05868,55.928,59.489,62.094,63.87,65.421,66.099,66.983,67.926,69.292,70.265,71.028,71.993,1439529,1647412,1886848,2186894,2680018,3115787,3086876,3089353,3219994,3430388,3677780,3921278 +"Asia","Malaysia",1831.132894,1810.066992,2036.884944,2277.742396,2849.09478,3827.921571,4920.355951,5249.802653,7277.912802,10132.90964,10206.97794,12451.6558,48.463,52.102,55.737,59.371,63.01,65.256,68,69.5,70.693,71.938,73.044,74.241,6748378,7739235,8906385,10154878,11441462,12845381,14441916,16331785,18319502,20476091,22662365,24821286 +"Asia","Mongolia",786.5668575,912.6626085,1056.353958,1226.04113,1421.741975,1647.511665,2000.603139,2338.008304,1785.402016,1902.2521,2140.739323,3095.772271,42.244,45.248,48.251,51.253,53.754,55.491,57.489,60.222,61.271,63.625,65.033,66.803,800663,882134,1010280,1149500,1320500,1528000,1756032,2015133,2312802,2494803,2674234,2874127 +"Asia","Myanmar",331,350,388,349,357,371,424,385,347,415,611,944,36.319,41.905,45.108,49.379,53.07,56.059,58.056,58.339,59.32,60.328,59.908,62.069,20092996,21731844,23634436,25870271,28466390,31528087,34680442,38028578,40546538,43247867,45598081,47761980 +"Asia","Nepal",545.8657229,597.9363558,652.3968593,676.4422254,674.7881296,694.1124398,718.3730947,775.6324501,897.7403604,1010.892138,1057.206311,1091.359778,36.157,37.686,39.393,41.472,43.971,46.748,49.594,52.537,55.727,59.426,61.34,63.785,9182536,9682338,10332057,11261690,12412593,13933198,15796314,17917180,20326209,23001113,25873917,28901790 +"Asia","Oman",1828.230307,2242.746551,2924.638113,4720.942687,10618.03855,11848.34392,12954.79101,18115.22313,18616.70691,19702.05581,19774.83687,22316.19287,37.578,40.08,43.165,46.988,52.143,57.367,62.728,67.734,71.197,72.499,74.193,75.64,507833,561977,628164,714775,829050,1004533,1301048,1593882,1915208,2283635,2713462,3204897 +"Asia","Pakistan",684.5971438,747.0835292,803.3427418,942.4082588,1049.938981,1175.921193,1443.429832,1704.686583,1971.829464,2049.350521,2092.712441,2605.94758,43.436,45.557,47.67,49.8,51.929,54.043,56.158,58.245,60.838,61.818,63.61,65.483,41346560,46679944,53100671,60641899,69325921,78152686,91462088,105186881,120065004,135564834,153403524,169270617 +"Asia","Philippines",1272.880995,1547.944844,1649.552153,1814.12743,1989.37407,2373.204287,2603.273765,2189.634995,2279.324017,2536.534925,2650.921068,3190.481016,47.752,51.334,54.757,56.393,58.065,60.06,62.082,64.151,66.458,68.564,70.303,71.688,22438691,26072194,30325264,35356600,40850141,46850962,53456774,60017788,67185766,75012988,82995088,91077287 +"Asia","Saudi Arabia",6459.554823,8157.591248,11626.41975,16903.04886,24837.42865,34167.7626,33693.17525,21198.26136,24841.61777,20586.69019,19014.54118,21654.83194,39.875,42.868,45.914,49.901,53.886,58.69,63.012,66.295,68.768,70.533,71.626,72.777,4005677,4419650,4943029,5618198,6472756,8128505,11254672,14619745,16945857,21229759,24501530,27601038 +"Asia","Singapore",2315.138227,2843.104409,3674.735572,4977.41854,8597.756202,11210.08948,15169.16112,18861.53081,24769.8912,33519.4766,36023.1054,47143.17964,60.396,63.179,65.798,67.946,69.521,70.795,71.76,73.56,75.788,77.158,78.77,79.972,1127000,1445929,1750200,1977600,2152400,2325300,2651869,2794552,3235865,3802309,4197776,4553009 +"Asia","Sri Lanka",1083.53203,1072.546602,1074.47196,1135.514326,1213.39553,1348.775651,1648.079789,1876.766827,2153.739222,2664.477257,3015.378833,3970.095407,57.593,61.456,62.192,64.266,65.042,65.949,68.757,69.011,70.379,70.457,70.815,72.396,7982342,9128546,10421936,11737396,13016733,14116836,15410151,16495304,17587060,18698655,19576783,20378239 +"Asia","Syria",1643.485354,2117.234893,2193.037133,1881.923632,2571.423014,3195.484582,3761.837715,3116.774285,3340.542768,4014.238972,4090.925331,4184.548089,45.883,48.284,50.305,53.655,57.296,61.195,64.59,66.974,69.249,71.527,73.053,74.143,3661549,4149908,4834621,5680812,6701172,7932503,9410494,11242847,13219062,15081016,17155814,19314747 +"Asia","Taiwan",1206.947913,1507.86129,1822.879028,2643.858681,4062.523897,5596.519826,7426.354774,11054.56175,15215.6579,20206.82098,23235.42329,28718.27684,58.5,62.4,65.2,67.5,69.39,70.59,72.16,73.4,74.26,75.25,76.99,78.4,8550362,10164215,11918938,13648692,15226039,16785196,18501390,19757799,20686918,21628605,22454239,23174294 +"Asia","Thailand",757.7974177,793.5774148,1002.199172,1295.46066,1524.358936,1961.224635,2393.219781,2982.653773,4616.896545,5852.625497,5913.187529,7458.396327,50.848,53.63,56.061,58.285,60.405,62.494,64.597,66.084,67.298,67.521,68.564,70.616,21289402,25041917,29263397,34024249,39276153,44148285,48827160,52910342,56667095,60216677,62806748,65068149 +"Asia","Vietnam",605.0664917,676.2854478,772.0491602,637.1232887,699.5016441,713.5371196,707.2357863,820.7994449,989.0231487,1385.896769,1764.456677,2441.576404,40.412,42.887,45.363,47.838,50.254,55.764,58.816,62.82,67.662,70.672,73.017,74.249,26246839,28998543,33796140,39463910,44655014,50533506,56142181,62826491,69940728,76048996,80908147,85262356 +"Asia","West Bank and Gaza",1515.592329,1827.067742,2198.956312,2649.715007,3133.409277,3682.831494,4336.032082,5107.197384,6017.654756,7110.667619,4515.487575,3025.349798,43.16,45.671,48.127,51.631,56.532,60.765,64.406,67.046,69.718,71.096,72.37,73.422,1030585,1070439,1133134,1142636,1089572,1261091,1425876,1691210,2104779,2826046,3389578,4018332 +"Asia","Yemen Rep.",781.7175761,804.8304547,825.6232006,862.4421463,1265.047031,1829.765177,1977.55701,1971.741538,1879.496673,2117.484526,2234.820827,2280.769906,32.548,33.97,35.18,36.984,39.848,44.175,49.113,52.922,55.599,58.02,60.308,62.698,4963829,5498090,6120081,6740785,7407075,8403990,9657618,11219340,13367997,15826497,18701257,22211743 +"Europe","Albania",1601.056136,1942.284244,2312.888958,2760.196931,3313.422188,3533.00391,3630.880722,3738.932735,2497.437901,3193.054604,4604.211737,5937.029526,55.23,59.28,64.82,66.22,67.69,68.93,70.42,72,71.581,72.95,75.651,76.423,1282697,1476505,1728137,1984060,2263554,2509048,2780097,3075321,3326498,3428038,3508512,3600523 +"Europe","Austria",6137.076492,8842.59803,10750.72111,12834.6024,16661.6256,19749.4223,21597.08362,23687.82607,27042.01868,29095.92066,32417.60769,36126.4927,66.8,67.48,69.54,70.14,70.63,72.17,73.18,74.94,76.04,77.51,78.98,79.829,6927772,6965860,7129864,7376998,7544201,7568430,7574613,7578903,7914969,8069876,8148312,8199783 +"Europe","Belgium",8343.105127,9714.960623,10991.20676,13149.04119,16672.14356,19117.97448,20979.84589,22525.56308,25575.57069,27561.19663,30485.88375,33692.60508,68,69.24,70.25,70.94,71.44,72.8,73.93,75.35,76.46,77.53,78.32,79.441,8730405,8989111,9218400,9556500,9709100,9821800,9856303,9870200,10045622,10199787,10311970,10392226 +"Europe","Bosnia and Herzegovina",973.5331948,1353.989176,1709.683679,2172.352423,2860.16975,3528.481305,4126.613157,4314.114757,2546.781445,4766.355904,6018.975239,7446.298803,53.82,58.45,61.93,64.79,67.45,69.86,70.69,71.14,72.178,73.244,74.09,74.852,2791000,3076000,3349000,3585000,3819000,4086000,4172693,4338977,4256013,3607000,4165416,4552198 +"Europe","Bulgaria",2444.286648,3008.670727,4254.337839,5577.0028,6597.494398,7612.240438,8224.191647,8239.854824,6302.623438,5970.38876,7696.777725,10680.79282,59.6,66.61,69.51,70.42,70.9,70.81,71.08,71.34,71.19,70.32,72.14,73.005,7274900,7651254,8012946,8310226,8576200,8797022,8892098,8971958,8658506,8066057,7661799,7322858 +"Europe","Croatia",3119.23652,4338.231617,5477.890018,6960.297861,9164.090127,11305.38517,13221.82184,13822.58394,8447.794873,9875.604515,11628.38895,14619.22272,61.21,64.77,67.13,68.5,69.61,70.64,70.46,71.52,72.527,73.68,74.876,75.748,3882229,3991242,4076557,4174366,4225310,4318673,4413368,4484310,4494013,4444595,4481020,4493312 +"Europe","Czech Republic",6876.14025,8256.343918,10136.86713,11399.44489,13108.4536,14800.16062,15377.22855,16310.4434,14297.02122,16048.51424,17596.21022,22833.30851,66.87,69.03,69.9,70.38,70.29,70.71,70.96,71.58,72.4,74.01,75.51,76.486,9125183,9513758,9620282,9835109,9862158,10161915,10303704,10311597,10315702,10300707,10256295,10228744 +"Europe","Denmark",9692.385245,11099.65935,13583.31351,15937.21123,18866.20721,20422.9015,21688.04048,25116.17581,26406.73985,29804.34567,32166.50006,35278.41874,70.78,71.81,72.35,72.96,73.47,74.69,74.63,74.8,75.33,76.11,77.18,78.332,4334000,4487831,4646899,4838800,4991596,5088419,5117810,5127024,5171393,5283663,5374693,5468120 +"Europe","Finland",6424.519071,7545.415386,9371.842561,10921.63626,14358.8759,15605.42283,18533.15761,21141.01223,20647.16499,23723.9502,28204.59057,33207.0844,66.55,67.49,68.75,69.83,70.87,72.52,74.55,74.83,75.7,77.13,78.37,79.313,4090500,4324000,4491443,4605744,4639657,4738902,4826933,4931729,5041039,5134406,5193039,5238460 +"Europe","France",7029.809327,8662.834898,10560.48553,12999.91766,16107.19171,18292.63514,20293.89746,22066.44214,24703.79615,25889.78487,28926.03234,30470.0167,67.41,68.93,70.51,71.55,72.38,73.83,74.89,76.34,77.46,78.64,79.59,80.657,42459667,44310863,47124000,49569000,51732000,53165019,54433565,55630100,57374179,58623428,59925035,61083916 +"Europe","Germany",7144.114393,10187.82665,12902.46291,14745.62561,18016.18027,20512.92123,22031.53274,24639.18566,26505.30317,27788.88416,30035.80198,32170.37442,67.5,69.1,70.3,70.8,71,72.5,73.8,74.847,76.07,77.34,78.67,79.406,69145952,71019069,73739117,76368453,78717088,78160773,78335266,77718298,80597764,82011073,82350671,82400996 +"Europe","Greece",3530.690067,4916.299889,6017.190733,8513.097016,12724.82957,14195.52428,15268.42089,16120.52839,17541.49634,18747.69814,22514.2548,27538.41188,65.86,67.86,69.51,71,72.34,73.68,75.24,76.67,77.03,77.869,78.256,79.483,7733250,8096218,8448233,8716441,8888628,9308479,9786480,9974490,10325429,10502372,10603863,10706290 +"Europe","Hungary",5263.673816,6040.180011,7550.359877,9326.64467,10168.65611,11674.83737,12545.99066,12986.47998,10535.62855,11712.7768,14843.93556,18008.94444,64.03,66.41,67.96,69.5,69.76,69.95,69.39,69.58,69.17,71.04,72.59,73.338,9504000,9839000,10063000,10223422,10394091,10637171,10705535,10612740,10348684,10244684,10083313,9956108 +"Europe","Iceland",7267.688428,9244.001412,10350.15906,13319.89568,15798.06362,19654.96247,23269.6075,26923.20628,25144.39201,28061.09966,31163.20196,36180.78919,72.49,73.47,73.68,73.73,74.46,76.11,76.99,77.23,78.77,78.95,80.5,81.757,147962,165110,182053,198676,209275,221823,233997,244676,259012,271192,288030,301931 +"Europe","Ireland",5210.280328,5599.077872,6631.597314,7655.568963,9530.772896,11150.98113,12618.32141,13872.86652,17558.81555,24521.94713,34077.04939,40675.99635,66.91,68.9,70.29,71.08,71.28,72.03,73.1,74.36,75.467,76.122,77.783,78.885,2952156,2878220,2830000,2900100,3024400,3271900,3480000,3539900,3557761,3667233,3879155,4109086 +"Europe","Italy",4931.404155,6248.656232,8243.58234,10022.40131,12269.27378,14255.98475,16537.4835,19207.23482,22013.64486,24675.02446,27968.09817,28569.7197,65.94,67.81,69.24,71.06,72.19,73.48,74.98,76.42,77.44,78.82,80.24,80.546,47666000,49182000,50843200,52667100,54365564,56059245,56535636,56729703,56840847,57479469,57926999,58147733 +"Europe","Montenegro",2647.585601,3682.259903,4649.593785,5907.850937,7778.414017,9595.929905,11222.58762,11732.51017,7003.339037,6465.613349,6557.194282,9253.896111,59.164,61.448,63.728,67.178,70.636,73.066,74.101,74.865,75.435,75.445,73.981,74.543,413834,442829,474528,501035,527678,560073,562548,569473,621621,692651,720230,684736 +"Europe","Netherlands",8941.571858,11276.19344,12790.84956,15363.25136,18794.74567,21209.0592,21399.46046,23651.32361,26790.94961,30246.13063,33724.75778,36797.93332,72.13,72.99,73.23,73.82,73.75,75.24,76.05,76.83,77.42,78.03,78.53,79.762,10381988,11026383,11805689,12596822,13329874,13852989,14310401,14665278,15174244,15604464,16122830,16570613 +"Europe","Norway",10095.42172,11653.97304,13450.40151,16361.87647,18965.05551,23311.34939,26298.63531,31540.9748,33965.66115,41283.16433,44683.97525,49357.19017,72.67,73.44,73.47,74.08,74.34,75.37,75.97,75.89,77.32,78.32,79.05,80.196,3327728,3491938,3638919,3786019,3933004,4043205,4114787,4186147,4286357,4405672,4535591,4627926 +"Europe","Poland",4029.329699,4734.253019,5338.752143,6557.152776,8006.506993,9508.141454,8451.531004,9082.351172,7738.881247,10159.58368,12002.23908,15389.92468,61.31,65.77,67.64,69.61,70.85,70.67,71.32,70.98,70.99,72.75,74.67,75.563,25730551,28235346,30329617,31785378,33039545,34621254,36227381,37740710,38370697,38654957,38625976,38518241 +"Europe","Portugal",3068.319867,3774.571743,4727.954889,6361.517993,9022.247417,10172.48572,11753.84291,13039.30876,16207.26663,17641.03156,19970.90787,20509.64777,59.82,61.51,64.39,66.6,69.26,70.41,72.77,74.06,74.86,75.97,77.29,78.098,8526050,8817650,9019800,9103000,8970450,9662600,9859650,9915289,9927680,10156415,10433867,10642836 +"Europe","Romania",3144.613186,3943.370225,4734.997586,6470.866545,8011.414402,9356.39724,9605.314053,9696.273295,6598.409903,7346.547557,7885.360081,10808.47561,61.05,64.1,66.8,66.8,69.21,69.46,69.66,69.53,69.36,69.72,71.322,72.476,16630000,17829327,18680721,19284814,20662648,21658597,22356726,22686371,22797027,22562458,22404337,22276056 +"Europe","Serbia",3581.459448,4981.090891,6289.629157,7991.707066,10522.06749,12980.66956,15181.0927,15870.87851,9325.068238,7914.320304,7236.075251,9786.534714,57.996,61.685,64.531,66.914,68.7,70.3,70.162,71.218,71.659,72.232,73.213,74.002,6860147,7271135,7616060,7971222,8313288,8686367,9032824,9230783,9826397,10336594,10111559,10150265 +"Europe","Slovak Republic",5074.659104,6093.26298,7481.107598,8412.902397,9674.167626,10922.66404,11348.54585,12037.26758,9498.467723,12126.23065,13638.77837,18678.31435,64.36,67.45,70.33,70.98,70.35,70.45,70.8,71.08,71.38,72.71,73.8,74.663,3558137,3844277,4237384,4442238,4593433,4827803,5048043,5199318,5302888,5383010,5410052,5447502 +"Europe","Slovenia",4215.041741,5862.276629,7402.303395,9405.489397,12383.4862,15277.03017,17866.72175,18678.53492,14214.71681,17161.10735,20660.01936,25768.25759,65.57,67.85,69.15,69.18,69.82,70.97,71.063,72.25,73.64,75.13,76.66,77.926,1489518,1533070,1582962,1646912,1694510,1746919,1861252,1945870,1999210,2011612,2011497,2009245 +"Europe","Spain",3834.034742,4564.80241,5693.843879,7993.512294,10638.75131,13236.92117,13926.16997,15764.98313,18603.06452,20445.29896,24835.47166,28821.0637,64.94,66.66,69.69,71.44,73.06,74.39,76.3,76.9,77.57,78.77,79.78,80.941,28549870,29841614,31158061,32850275,34513161,36439000,37983310,38880702,39549438,39855442,40152517,40448191 +"Europe","Sweden",8527.844662,9911.878226,12329.44192,15258.29697,17832.02464,18855.72521,20667.38125,23586.92927,23880.01683,25266.59499,29341.63093,33859.74835,71.86,72.49,73.37,74.16,74.72,75.44,76.42,77.19,78.16,79.39,80.04,80.884,7124673,7363802,7561588,7867931,8122293,8251648,8325260,8421403,8718867,8897619,8954175,9031088 +"Europe","Switzerland",14734.23275,17909.48973,20431.0927,22966.14432,27195.11304,26982.29052,28397.71512,30281.70459,31871.5303,32135.32301,34480.95771,37506.41907,69.62,70.56,71.32,72.77,73.78,75.39,76.21,77.41,78.03,79.37,80.62,81.701,4815000,5126000,5666000,6063000,6401400,6316424,6468126,6649942,6995447,7193761,7361757,7554661 +"Europe","Turkey",1969.10098,2218.754257,2322.869908,2826.356387,3450.69638,4269.122326,4241.356344,5089.043686,5678.348271,6601.429915,6508.085718,8458.276384,43.585,48.079,52.098,54.336,57.005,59.507,61.036,63.108,66.146,68.835,70.845,71.777,22235677,25670939,29788695,33411317,37492953,42404033,47328791,52881328,58179144,63047647,67308928,71158647 +"Europe","United Kingdom",9979.508487,11283.17795,12477.17707,14142.85089,15895.11641,17428.74846,18232.42452,21664.78767,22705.09254,26074.53136,29478.99919,33203.26128,69.18,70.42,70.76,71.36,72.01,72.76,74.04,75.007,76.42,77.218,78.471,79.425,50430000,51430000,53292000,54959000,56079000,56179000,56339704,56981620,57866349,58808266,59912431,60776238 +"Oceania","Australia",10039.59564,10949.64959,12217.22686,14526.12465,16788.62948,18334.19751,19477.00928,21888.88903,23424.76683,26997.93657,30687.75473,34435.36744,69.12,70.33,70.93,71.1,71.93,73.49,74.74,76.32,77.56,78.83,80.37,81.235,8691212,9712569,10794968,11872264,13177000,14074100,15184200,16257249,17481977,18565243,19546792,20434176 +"Oceania","New Zealand",10556.57566,12247.39532,13175.678,14463.91893,16046.03728,16233.7177,17632.4104,19007.19129,18363.32494,21050.41377,23189.80135,25185.00911,69.39,70.26,71.24,71.52,71.89,72.22,73.84,74.32,76.33,77.55,79.11,80.204,1994794,2229407,2488550,2728150,2929100,3164900,3210650,3317166,3437674,3676187,3908037,4115771 diff --git a/data/inflammation.csv b/data/inflammation.csv new file mode 100644 index 000000000..07a2e6040 --- /dev/null +++ b/data/inflammation.csv @@ -0,0 +1,60 @@ +0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0 +0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1 +0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1 +0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1 +0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1 +0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1 +0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1 +0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1 +0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0 +0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0 +0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1 +0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1 +0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1 +0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0 +0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0 +0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0 +0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1 +0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0 +0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0 +0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1 +0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0 +0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0 +0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0 +0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0 +0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1 +0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0 +0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1 +0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1 +0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0 +0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1 +0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1 +0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0 +0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1 +0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1 +0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1 +0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0 +0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1 +0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0 +0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1 +0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1 +0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1 +0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0 +0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0 +0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1 +0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1 +0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0 +0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0 +0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1 +0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0 +0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1 +0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0 +0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0 +0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1 +0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1 +0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1 +0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1 +0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1 +0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1 +0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0 +0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0 diff --git a/discuss.md b/discuss.md new file mode 100644 index 000000000..a89a31ca1 --- /dev/null +++ b/discuss.md @@ -0,0 +1,10 @@ +--- +title: Discussion +--- + +Please see [our other R lesson][r-gap] for a different presentation of these concepts. + +[r-gap]: https://swcarpentry.github.io/r-novice-gapminder/ + + + diff --git a/fig/01-rstudio-script.png b/fig/01-rstudio-script.png new file mode 100644 index 000000000..babbd2949 Binary files /dev/null and b/fig/01-rstudio-script.png differ diff --git a/fig/01-rstudio.png b/fig/01-rstudio.png new file mode 100644 index 000000000..0840386af Binary files /dev/null and b/fig/01-rstudio.png differ diff --git a/fig/06-rmd-generate-figures.sh b/fig/06-rmd-generate-figures.sh new file mode 100755 index 000000000..4cc231322 --- /dev/null +++ b/fig/06-rmd-generate-figures.sh @@ -0,0 +1,7 @@ +inkscape --export-png=06-rmd-inequality.0.png 06-rmd-inequality.0.svg +# use ImageMagick to grab top and bottom halves +# (surely there's a better way ... too much space at the bottom of the first) +convert 06-rmd-inequality.0.png -crop 100%x50% tmp.png +mv tmp-0.png 06-rmd-inequality.1.png +mv tmp-1.png 06-rmd-inequality.2.png + diff --git a/fig/06-rmd-inequality.0.png b/fig/06-rmd-inequality.0.png new file mode 100644 index 000000000..aa6d3f1e9 Binary files /dev/null and b/fig/06-rmd-inequality.0.png differ diff --git a/fig/06-rmd-inequality.0.svg b/fig/06-rmd-inequality.0.svg new file mode 100644 index 000000000..b8953dcbe --- /dev/null +++ b/fig/06-rmd-inequality.0.svg @@ -0,0 +1,311 @@ + + + + + + + + + + image/svg+xml + + + + + + + c("a", "b", "c") + c("a", "c") + + + + + + + FALSE + TRUE + ?? + ?? + c("a", "b", "c") + c("a", "c") + + + + + + + FALSE + TRUE + c("a"... + FALSE + != + != + + diff --git a/fig/06-rmd-inequality.1.png b/fig/06-rmd-inequality.1.png new file mode 100644 index 000000000..580038505 Binary files /dev/null and b/fig/06-rmd-inequality.1.png differ diff --git a/fig/06-rmd-inequality.2.png b/fig/06-rmd-inequality.2.png new file mode 100644 index 000000000..d3f438dc1 Binary files /dev/null and b/fig/06-rmd-inequality.2.png differ diff --git a/fig/08-plot-ggplot2-rendered-axis-scale-1.png b/fig/08-plot-ggplot2-rendered-axis-scale-1.png new file mode 100644 index 000000000..3349b33e9 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-axis-scale-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-blank-ggplot-1.png b/fig/08-plot-ggplot2-rendered-blank-ggplot-1.png new file mode 100644 index 000000000..14c48d3bf Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-blank-ggplot-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ch1-sol-1.png b/fig/08-plot-ggplot2-rendered-ch1-sol-1.png new file mode 100644 index 000000000..6dcaa2a72 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ch1-sol-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ch2-sol-1.png b/fig/08-plot-ggplot2-rendered-ch2-sol-1.png new file mode 100644 index 000000000..8fae6da1e Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ch2-sol-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ch3-sol-1.png b/fig/08-plot-ggplot2-rendered-ch3-sol-1.png new file mode 100644 index 000000000..4fef0d7b8 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ch3-sol-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ch4a-sol-1.png b/fig/08-plot-ggplot2-rendered-ch4a-sol-1.png new file mode 100644 index 000000000..0f755f4c7 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ch4a-sol-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ch4b-sol-1.png b/fig/08-plot-ggplot2-rendered-ch4b-sol-1.png new file mode 100644 index 000000000..8728393e9 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ch4b-sol-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ch5-sol-1.png b/fig/08-plot-ggplot2-rendered-ch5-sol-1.png new file mode 100644 index 000000000..ab36d5124 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ch5-sol-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-facet-1.png b/fig/08-plot-ggplot2-rendered-facet-1.png new file mode 100644 index 000000000..bc7c4d02c Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-facet-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-ggplot-with-aes-1.png b/fig/08-plot-ggplot2-rendered-ggplot-with-aes-1.png new file mode 100644 index 000000000..70214d8b0 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-ggplot-with-aes-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lifeExp-layer-example-1-1.png b/fig/08-plot-ggplot2-rendered-lifeExp-layer-example-1-1.png new file mode 100644 index 000000000..fe80c06ad Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lifeExp-layer-example-1-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lifeExp-line-1.png b/fig/08-plot-ggplot2-rendered-lifeExp-line-1.png new file mode 100644 index 000000000..3d00bf53e Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lifeExp-line-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lifeExp-line-by-1.png b/fig/08-plot-ggplot2-rendered-lifeExp-line-by-1.png new file mode 100644 index 000000000..a5d0a052a Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lifeExp-line-by-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lifeExp-line-point-1.png b/fig/08-plot-ggplot2-rendered-lifeExp-line-point-1.png new file mode 100644 index 000000000..86a628f0c Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lifeExp-line-point-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lifeExp-vs-gdpPercap-scatter-1.png b/fig/08-plot-ggplot2-rendered-lifeExp-vs-gdpPercap-scatter-1.png new file mode 100644 index 000000000..44db5466d Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lifeExp-vs-gdpPercap-scatter-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lifeExp-vs-gdpPercap-scatter3-1.png b/fig/08-plot-ggplot2-rendered-lifeExp-vs-gdpPercap-scatter3-1.png new file mode 100644 index 000000000..44db5466d Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lifeExp-vs-gdpPercap-scatter3-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lm-fit-1.png b/fig/08-plot-ggplot2-rendered-lm-fit-1.png new file mode 100644 index 000000000..f819c105f Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lm-fit-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-lm-fit2-1.png b/fig/08-plot-ggplot2-rendered-lm-fit2-1.png new file mode 100644 index 000000000..d93c05d0e Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-lm-fit2-1.png differ diff --git a/fig/08-plot-ggplot2-rendered-theme-1.png b/fig/08-plot-ggplot2-rendered-theme-1.png new file mode 100644 index 000000000..e58d0cd70 Binary files /dev/null and b/fig/08-plot-ggplot2-rendered-theme-1.png differ diff --git a/fig/09-vectorization-rendered-ch2-sol-1.png b/fig/09-vectorization-rendered-ch2-sol-1.png new file mode 100644 index 000000000..99fe38be7 Binary files /dev/null and b/fig/09-vectorization-rendered-ch2-sol-1.png differ diff --git a/fig/09-vectorization-rendered-ch2-sol-2.png b/fig/09-vectorization-rendered-ch2-sol-2.png new file mode 100644 index 000000000..5b630819b Binary files /dev/null and b/fig/09-vectorization-rendered-ch2-sol-2.png differ diff --git a/fig/12-dplyr-rendered-unnamed-chunk-27-1.png b/fig/12-dplyr-rendered-unnamed-chunk-27-1.png new file mode 100644 index 000000000..bc7c4d02c Binary files /dev/null and b/fig/12-dplyr-rendered-unnamed-chunk-27-1.png differ diff --git a/fig/12-dplyr-rendered-unnamed-chunk-28-1.png b/fig/12-dplyr-rendered-unnamed-chunk-28-1.png new file mode 100644 index 000000000..bc7c4d02c Binary files /dev/null and b/fig/12-dplyr-rendered-unnamed-chunk-28-1.png differ diff --git a/fig/12-dplyr-rendered-unnamed-chunk-29-1.png b/fig/12-dplyr-rendered-unnamed-chunk-29-1.png new file mode 100644 index 000000000..75472eaee Binary files /dev/null and b/fig/12-dplyr-rendered-unnamed-chunk-29-1.png differ diff --git a/fig/12-plyr-fig1.png b/fig/12-plyr-fig1.png new file mode 100644 index 000000000..249bab4fa Binary files /dev/null and b/fig/12-plyr-fig1.png differ diff --git a/fig/12-plyr-fig1.tex b/fig/12-plyr-fig1.tex new file mode 100644 index 000000000..ded41a78c --- /dev/null +++ b/fig/12-plyr-fig1.tex @@ -0,0 +1,143 @@ +\documentclass[convert]{standalone} + +\usepackage{tikz} +\usepackage{colortbl} +\renewcommand{\familydefault}{\sfdefault} + +\begin{document} + +\begin{tikzpicture} + +% Headings + +\node (INPUT-LABEL) at (0, 5) {Input Data}; +\node (GROUP-LABEL) at (3, 5) {Split}; +\node (SUMMARY-LABEL) at (6, 5) {Apply}; +\node (OUTPUT-LABEL) at (9, 5) {Combine}; + + +% Data Nodes + +\node (INPUT) at (0, 2) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + a & 2 \\ \hline + a & 4 \\ \hline + b & 0 \\ \hline + b & 5 \\ \hline + c & 5 \\ \hline + c & 10 \\ \hline + \end{tabular} + +}; + +\node (GROUP-A) at (3, 4) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + a & 2 \\ \hline + a & 4 \\ \hline + \end{tabular} + +}; + +\node (GROUP-B) at (3, 2) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + b & 0 \\ \hline + b & 5 \\ \hline + \end{tabular} + +}; + +\node (GROUP-C) at (3, 0) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + c & 5 \\ \hline + c & 10 \\ \hline + \end{tabular} + +}; + +\node (SUMMARY-A) at (6, 4) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + a & 3.0 \\ \hline + \end{tabular} + +}; + +\node (SUMMARY-B) at (6, 2) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + b & 2.5 \\ \hline + \end{tabular} + +}; + +\node (SUMMARY-C) at (6, 0) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + c & 7.5 \\ \hline + \end{tabular} + +}; + +\node (OUPUT) at (9, 2) { + + \begin{tabular}{| c | r |} + \hline + \rowcolor[gray]{.7} + x & y \\ \hline + a & 3.0 \\ \hline + b & 2.5 \\ \hline + c & 7.5 \\ \hline + \end{tabular} + +}; + + +% Arrows + +\draw[->, to path={-> (\tikztotarget)}] + (INPUT) edge (GROUP-A) + (INPUT) edge (GROUP-B) + (INPUT) edge (GROUP-C) + + (GROUP-A) edge (SUMMARY-A) + (GROUP-B) edge (SUMMARY-B) + (GROUP-C) edge (SUMMARY-C) + + (SUMMARY-A) edge (OUPUT) + (SUMMARY-B) edge (OUPUT) + (SUMMARY-C) edge (OUPUT) +; + +\end{tikzpicture} + +\end{document} + +%------------------------ +% References +% https://tex.stackexchange.com/questions/251642/draw-arrows-between-nodes-with-tikz +% https://tex.stackexchange.com/questions/11866/compile-a-latex-document-into-a-png-image-thats-as-short-as-possible diff --git a/fig/12-plyr-fig2.png b/fig/12-plyr-fig2.png new file mode 100644 index 000000000..d00d25f5c Binary files /dev/null and b/fig/12-plyr-fig2.png differ diff --git a/fig/12-plyr-fig2.tex b/fig/12-plyr-fig2.tex new file mode 100644 index 000000000..56fdfcd3f --- /dev/null +++ b/fig/12-plyr-fig2.tex @@ -0,0 +1,64 @@ +\documentclass[convert]{standalone} + +\usepackage{array} +\usepackage{multirow} +\usepackage{rotating} +\usepackage{colortbl} +\renewcommand{\familydefault}{\sfdefault} +\renewcommand{\arraystretch}{2.2} + +\begin{document} + +\begin{tabular}{crccccc} + +& +& \multicolumn{4}{c}{Output} +\\ + +& %\cellcolor[gray]{0.7} +& \cellcolor[gray]{0.7}array +& \cellcolor[gray]{0.7}data frame +& \cellcolor[gray]{0.7}list +& \cellcolor[gray]{0.7}nothing +\\ + +& \cellcolor[gray]{0.7}array +& aaply +& adply +& alply +& a\_ply +\\ + +& \cellcolor[gray]{0.7}data frame +& daply +& ddply +& dlply +& d\_ply +\\ + +& \cellcolor[gray]{0.7} list +& laply +& ldply +& llply +& l\_ply +\\ + +& \cellcolor[gray]{0.7}n replicates +& raply +& rdply +& rlply +& r\_ply +\\ + +\multirow{-5}{*}{\rotatebox[origin=c]{90}{Input}} +& \cellcolor[gray]{0.7}function arguments +& maply +& mdply +& mlply +& m\_ply +\\ + +\end{tabular} + + +\end{document} diff --git a/fig/12-plyr-generate-figures.sh b/fig/12-plyr-generate-figures.sh new file mode 100755 index 000000000..9236d34e0 --- /dev/null +++ b/fig/12-plyr-generate-figures.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +pdflatex -shell-escape 12-plyr-fig1.tex + +rm 12-plyr-fig1.aux 12-plyr-fig1.log 12-plyr-fig1.pdf + +pdflatex -shell-escape 12-plyr-fig2.tex + +rm 12-plyr-fig2.aux 12-plyr-fig2.log 12-plyr-fig2.pdf + diff --git a/fig/13-dplyr-fig1.png b/fig/13-dplyr-fig1.png new file mode 100644 index 000000000..7f3067a3c Binary files /dev/null and b/fig/13-dplyr-fig1.png differ diff --git a/fig/13-dplyr-fig2.png b/fig/13-dplyr-fig2.png new file mode 100644 index 000000000..caa86d462 Binary files /dev/null and b/fig/13-dplyr-fig2.png differ diff --git a/fig/13-dplyr-fig3.png b/fig/13-dplyr-fig3.png new file mode 100644 index 000000000..ae00ce386 Binary files /dev/null and b/fig/13-dplyr-fig3.png differ diff --git a/fig/13-dplyr-generate-figures.R b/fig/13-dplyr-generate-figures.R new file mode 100644 index 000000000..4c3f4b223 --- /dev/null +++ b/fig/13-dplyr-generate-figures.R @@ -0,0 +1,383 @@ +# export figures manually +library(DiagrammeR) +##################################### 13-dplyr-fig2.png #####################################) +grViz('digraph html { + table1 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
abcd
>]; + + table2 [shape=none, margin=0, label=< + + + + + + + + + + + + + + + + + + + + +
ac
>]; + + table1:f1:s -> table2:f1:s + table1:f0:n -> table2:f0:n + + subgraph { + rank = same; table1; table2; + } + + labelloc="t"; + fontname="Courier"; + label="select(data.frame, a, c)"; + } + ') + +##################################### 13-dplyr-fig2.png ##################################### +grViz('digraph html { + rankdir=LR; + table1 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
abcd
1
1
2
2
3
3
>]; + table2 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + + +
abcd
1
1
>]; + table3 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + +
abcd
2
2
>]; + table4 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + +
abcd
3
3
>]; + + table1:f0 -> table2:f0 + table1:f1 -> table3:f1 + table1:f2 -> table4:f2 + + + subgraph { + rank = same; table2; table3 ;table4; + } + + labelloc="t"; + fontname="Courier"; + label="gapminder %>%\\l\tgroup_by(a)"; + } + ') + +##################################### 13-dplyr-fig3.png ##################################### +grViz('digraph html { + rankdir=LR; + + table1 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
abcd
1
1
2
2
3
3
>]; + + table2 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + +
abcd
1
1
>]; + + table3 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + +
abcd
2
2
>]; + + table4 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + +
abcd
3
3
>]; + + table5 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + +
amean_b
1
2
3
>]; + + + table1:f0 -> table2:f0 + table1:f1 -> table3:f1 + table1:f2 -> table4:f2 + table2:f3:n -> table5:f0 + table3:f3 -> table5:f1 + table4:f3 -> table5:f2:w + + subgraph { + table1; table2; table3 ;table4; table5 + } + + subgraph { + rank = same; table2; table3; table4; + } + + labelloc="t"; + fontname="Courier"; + label="gapminder %>%\\l\tgroup_by(a) %>%\\l\tsummarize(mean_b=mean(b))\\l"; + } + ') diff --git a/fig/14-knitr-markdown-rendered-rmd_to_html_fig-1.png b/fig/14-knitr-markdown-rendered-rmd_to_html_fig-1.png new file mode 100644 index 000000000..976f7bc79 Binary files /dev/null and b/fig/14-knitr-markdown-rendered-rmd_to_html_fig-1.png differ diff --git a/fig/14-tidyr-fig1.png b/fig/14-tidyr-fig1.png new file mode 100644 index 000000000..4ce006667 Binary files /dev/null and b/fig/14-tidyr-fig1.png differ diff --git a/fig/14-tidyr-fig2.png b/fig/14-tidyr-fig2.png new file mode 100644 index 000000000..7287d0194 Binary files /dev/null and b/fig/14-tidyr-fig2.png differ diff --git a/fig/14-tidyr-fig3.png b/fig/14-tidyr-fig3.png new file mode 100644 index 000000000..4c13aa57d Binary files /dev/null and b/fig/14-tidyr-fig3.png differ diff --git a/fig/14-tidyr-fig3.svg b/fig/14-tidyr-fig3.svg new file mode 100644 index 000000000..6f756ef15 --- /dev/null +++ b/fig/14-tidyr-fig3.svg @@ -0,0 +1,269 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ID +a1 +a2 +a3 +ID +2 +1 +3 +2 +1 +3 +2 +1 +3 +2 +1 +3 +a1 +a2 +a3 +a1 +a2 +a3 +a1 +a2 +a3 +key +value +wide format +long format +pivot_longer(data, cols = c("a1", "a2", "a3"), names_to = "key", values_to = "value") + + + + + + + + + + + + + + + + +ID +a1 +a2 +a3 +2 +1 +3 + + + + +ID +2 +1 +3 + + + + +ID +2 +1 +3 + + + + + + + + + + + + + + + + +ID +a1 +a2 +a3 +2 +1 +3 + + + + +ID +2 +1 +3 + + + + +ID +2 +1 +3 + + + + + + + + + + + + + +ID +2 +1 +3 + + + + +ID +2 +1 +3 + + + + +ID +2 +1 +3 + + + +a1 +a2 +a3 + + + +a1 +a2 +a3 + + + +a1 +a2 +a3 + + + + + + + + +separate byselected columns + + + + + + + + +convert column names to column + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +name columns with keyand value arguments + diff --git a/fig/14-tidyr-fig4.png b/fig/14-tidyr-fig4.png new file mode 100644 index 000000000..fd5d68c64 Binary files /dev/null and b/fig/14-tidyr-fig4.png differ diff --git a/fig/14-tidyr-generate-figures.R b/fig/14-tidyr-generate-figures.R new file mode 100644 index 000000000..9ed954ae4 --- /dev/null +++ b/fig/14-tidyr-generate-figures.R @@ -0,0 +1,385 @@ +# export figures manually +library(DiagrammeR) +##################################### 14-tidyr-fig1.png ##################################### +grViz('digraph html { + + table1 [shape=none, margin=0, label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDa1a2a3
>]; + + table2 [shape=none, margin=0,label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDID2A
1a1
2a1
3a1
1a2
2a2
3a2
1a3
2a3
3a3
>]; + + subgraph { + rank = same; table1; table2; + } + + + labelloc="t"; + fontname="Courier"; + label="wide vs long"; + } + ') + +##################################### 14-tidyr-fig2.png ##################################### +grViz('digraph html { + table1 [shape=none, margin=0, label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
continentcountrygdpPercap_1952gdpPercap_1957gdpPercap_...lifeExp_1952lifeExp_1957lifeExp_...pop_1952pop_1957pop_...
AfricaAlgeria
AfricaAngola
......
>]; + + labelloc="t"; + fontname="Courier"; + label="wide format"; + } + ') + +##################################### 14-tidyr-fig3.png ##################################### +grViz('digraph html { + + table1 [shape=none, margin=0, label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
continentcountryobstype_yearobs_value
AfricaAlgeriagdpPercap_1952
AfricaAlgeriagdpPercap_1957
AfricaAlgeriagdpPercap_...
AfricaAlgerialifeExp_1952
AfricaAlgerialifeExp_1957
AfricaAlgerialifeExp_...
AfricaAlgeriapop_1952
AfricaAlgeriapop_1957
AfricaAlgeriapop_...
AfricaAngolagdpPercap_1952
AfricaAngolagdpPercap_1957
AfricaAngolagdpPercap_...
AfricaAngolalifeExp_1952
AfricaAngolalifeExp_1957
AfricaAngolalifeExp_...
AfricaAngolapop_1952
AfricaAngolapop_1957
AfricaAngolapop_...
Africa...gdpPercap_1952
Africa...gdpPercap_1957
Africa...gdpPercap_...
Africa...lifeExp_1952
Africa...lifeExp_1957
Africa...lifeExp_...
Africa...pop_1952
Africa...pop_1957
Africa...pop_...
>]; + + labelloc="t"; + fontname="Courier"; + label="long format"; + } + ') diff --git a/fig/New_R_Markdown.png b/fig/New_R_Markdown.png new file mode 100644 index 000000000..8542fe9bd Binary files /dev/null and b/fig/New_R_Markdown.png differ diff --git a/fig/bad_layout.png b/fig/bad_layout.png new file mode 100644 index 000000000..fcfda0c5a Binary files /dev/null and b/fig/bad_layout.png differ diff --git a/fig/rmd-06-equality.0.svg b/fig/rmd-06-equality.0.svg new file mode 100644 index 000000000..9671b0b3e --- /dev/null +++ b/fig/rmd-06-equality.0.svg @@ -0,0 +1,288 @@ + + + + + + + + + + image/svg+xml + + + + + + + c("a", "a", "a") + c("a", "c") + + + + + + + TRUE + FALSE + ?? + ?? + c("a", "a", "a") + c("a", "c") + + + + + + + TRUE + FALSE + c("a"... + TRUE + + diff --git a/fig/rmd-06-equality.1.png b/fig/rmd-06-equality.1.png new file mode 100644 index 000000000..f4152a338 Binary files /dev/null and b/fig/rmd-06-equality.1.png differ diff --git a/fig/rmd-06-equality.2.png b/fig/rmd-06-equality.2.png new file mode 100644 index 000000000..e33f4cf4f Binary files /dev/null and b/fig/rmd-06-equality.2.png differ diff --git a/fig/software-carpentry-banner.png b/fig/software-carpentry-banner.png new file mode 100644 index 000000000..746a9c53c Binary files /dev/null and b/fig/software-carpentry-banner.png differ diff --git a/fig/visual_mode_icon.png b/fig/visual_mode_icon.png new file mode 100644 index 000000000..d224e3cee Binary files /dev/null and b/fig/visual_mode_icon.png differ diff --git a/index.md b/index.md new file mode 100644 index 000000000..4606f0759 --- /dev/null +++ b/index.md @@ -0,0 +1,37 @@ +--- +site: sandpaper::sandpaper_site +--- + +*an introduction to R for non-programmers using gapminder data* + +The goal of this lesson is to teach novice programmers to write modular code +and best practices for using R for data analysis. R is commonly used in many +scientific disciplines for statistical analysis and its array of third-party +packages. We find that many scientists who come to Software Carpentry workshops +use R and want to learn more. The emphasis of these materials is to give +attendees a strong foundation in the fundamentals of R, and to teach best +practices for scientific computing: breaking down analyses into modular units, +task automation, and encapsulation. + +Note that this workshop will focus on teaching the fundamentals of the +programming language R, and will not teach statistical analysis. + +The lesson contains more material than can be taught in a day. The [instructor notes page](instructors/instructor-notes.md) has some suggested lesson plans suitable for a one or half day workshop. + +A variety of third party packages are used throughout this workshop. These +are not necessarily the best, nor are they comprehensive, but they are +packages we find useful, and have been chosen primarily for their +usability. + +:::::::::::::::::::::::::::::::::::::::::: prereq + +## Prerequisites + +Understand that computers store data and instructions (programs, scripts etc.) in files. +Files are organised in directories (folders). +Know how to access files not in the working directory by specifying the path. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/instructor-notes.md b/instructor-notes.md new file mode 100644 index 000000000..83d1925ef --- /dev/null +++ b/instructor-notes.md @@ -0,0 +1,135 @@ +--- +title: Instructor Notes +--- + +## Timing + +Leave about 30 minutes at the start of each workshop and another 15 mins +at the start of each session for technical difficulties like WiFi and +installing things (even if you asked students to install in advance, longer if +not). + +## Lesson Plans + +The lesson contains much more material than can be taught in a day. +Instructors will need to pick an appropriate subset of episodes to use +in a standard one day course. + +Some suggested paths through the material are: + +(suggested by [@liz-is](https://github.com/swcarpentry/r-novice-gapminder/issues/104#issuecomment-276529213)) + +- 01 Introduction to R and RStudio +- 04 Data Structures +- 05 Exploring Data Frames ("Realistic example" section onwards) +- 08 Creating Publication-Quality Graphics with ggplot2 +- 10 Functions Explained +- 13 Dataframe Manipulation with dplyr +- 15 Producing Reports With knitr + +(suggested by [@naupaka](https://github.com/swcarpentry/r-novice-gapminder/issues/104#issuecomment-312547509)) + +- 01 Introduction to R and RStudio +- 02 Project Management With RStudio +- 03 Seeking Help +- 04 Data Structures +- 05 Exploring Data Frames +- 06 Subsetting Data +- 09 Vectorization +- 08 Creating Publication-Quality Graphics with ggplot2 *OR* + 13 Dataframe Manipulation with dplyr +- 15 Producing Reports With knitr + +A half day course could consist of (suggested by [@karawoo](https://github.com/swcarpentry/r-novice-gapminder/issues/104#issuecomment-277599864)): + +- 01 Introduction to R and RStudio +- 04 Data Structures (only creating vectors with `c()`) +- 05 Exploring Data Frames ("Realistic example" section onwards) +- 06 Subsetting Data (excluding factor, matrix and list subsetting) +- 08 Creating Publication-Quality Graphics with ggplot2 + +## Setting up git in RStudio + +There can be difficulties linking git to RStudio depending on the +operating system and the version of the operating system. To make sure +Git is properly installed and configured, the learners should go to +the Options window in the RStudio application. + +- **Mac OS X:** + - Go RStudio -> Preferences... -> Git/SVN + - Check and see whether there is a path to a file in the "Git executable" window. If not, the next challenge is figuring out where Git is located. + - In the terminal enter `which git` and you will get a path to the git executable. In the "Git executable" window you may have difficulties finding the directory since OS X hides many of the operating system files. While the file selection window is open, pressing "Command-Shift-G" will pop up a text entry box where you will be able to type or paste in the full path to your git executable: e.g. /usr/bin/git or whatever else it might be. +- **Windows:** + - Go Tools -> Global options... -> Git/SVN + - If you use the Software Carpentry Installer, then 'git.exe' should be installed at `C:/Program Files/Git/bin/git.exe`. + +To prevent the learners from having to re-enter their password each time they push a commit to GitHub, this command (which can be run from a bash prompt) will make it so they only have to enter their password once: + +```bash +$ git config --global credential.helper 'cache --timeout=10000000' +``` + +## RStudio Color Preview + +RStudio has a feature to preview the color for certain named colors and hexadecimal colors. This may confuse or distract learners (and instructors) who are not expecting it. + +Mainly, this is likely to come up during the episode on "Data Structures" with the following code block: + +```r +cats <- data.frame(coat = c("calico", "black", "tabby"), + weight = c(2.1, 5.0, 3.2), + likes_string = c(1, 0, 1)) +``` + +This option can be turned off and on in the following menu setting: +Tools -> Global Options -> Code -> Display -> Enable preview of named and hexadecimal colors (under "Syntax") + +## Pulling in Data + +The easiest way to get the data used in this lesson during a workshop is to have +attendees download the raw data from [gapminder-data] and +[gapminder-data-wide]. + +Attendees can use the `File - Save As` dialog in their browser to save the file. + +## Overall + +Make sure to emphasize good practices: put code in scripts, and make +sure they're version controlled. Encourage students to create script +files for challenges. + +If you're working in a cloud environment, get them to upload the +gapminder data after the second lesson. + +Make sure to emphasize that matrices are vectors underneath the hood +and data frames are lists underneath the hood: this will explain a +lot of the esoteric behaviour encountered in basic operations. + +Vector recycling and function stacks are probably best explained +with diagrams on a whiteboard. + +Be sure to actually go through examples of an R help page: help files +can be intimidating at first, but knowing how to read them is tremendously +useful. + +Be sure to show the CRAN task views, look at one of the topics. + +There's a lot of content: move quickly through the earlier lessons. Their +extensiveness is mostly for purposes of learning by osmosis: so that their +memory will trigger later when they encounter a problem or some esoteric behaviour. + +Key lessons to take time on: + +- Data subsetting - conceptually difficult for novices +- Functions - learners especially struggle with this +- Data structures - worth being thorough, but you can go through it quickly. + +Don't worry about being correct or knowing the material back-to-front. Use +mistakes as teaching moments: the most vital skill you can impart is how to +debug and recover from unexpected errors. + +[gapminder-data]: data/gapminder_data.csv +[gapminder-data-wide]: data/gapminder_wide.csv + + + diff --git a/learner-profiles.md b/learner-profiles.md new file mode 100644 index 000000000..434e335aa --- /dev/null +++ b/learner-profiles.md @@ -0,0 +1,5 @@ +--- +title: FIXME +--- + +This is a placeholder file. Please add content here. diff --git a/md5sum.txt b/md5sum.txt new file mode 100644 index 000000000..f846e9521 --- /dev/null +++ b/md5sum.txt @@ -0,0 +1,26 @@ +"file" "checksum" "built" "date" +"CODE_OF_CONDUCT.md" "c93c83c630db2fe2462240bf72552548" "site/built/CODE_OF_CONDUCT.md" "2024-11-19" +"LICENSE.md" "b24ebbb41b14ca25cf6b8216dda83e5f" "site/built/LICENSE.md" "2024-11-19" +"config.yaml" "8b9d63dd3c46d5b4d5fa4219b51a0dfc" "site/built/config.yaml" "2024-11-19" +"index.md" "86c8fb559b13d1695d55b52dd6cbf574" "site/built/index.md" "2024-11-19" +"episodes/01-rstudio-intro.Rmd" "04f6b758558750cef962768d78dd63b0" "site/built/01-rstudio-intro.md" "2024-11-19" +"episodes/02-project-intro.Rmd" "cd60cc3116d4f6be92f03f5cc51bcc3b" "site/built/02-project-intro.md" "2024-11-19" +"episodes/03-seeking-help.Rmd" "d24c310b8f36930e70379458f3c93461" "site/built/03-seeking-help.md" "2024-11-19" +"episodes/04-data-structures-part1.Rmd" "afc6c3ced3677ab088457152f8d84b54" "site/built/04-data-structures-part1.md" "2024-11-19" +"episodes/05-data-structures-part2.Rmd" "95c5dd30b8288090ce89ecbf2d3072bd" "site/built/05-data-structures-part2.md" "2024-11-19" +"episodes/06-data-subsetting.Rmd" "5d4ce8731ab37ddea81874d63ae1ce86" "site/built/06-data-subsetting.md" "2024-11-19" +"episodes/07-control-flow.Rmd" "6a8691c8668737e4202f49b52aeb8ac6" "site/built/07-control-flow.md" "2024-11-19" +"episodes/08-plot-ggplot2.Rmd" "d694904459c32b9e35acd872830ee75c" "site/built/08-plot-ggplot2.md" "2024-11-19" +"episodes/09-vectorization.Rmd" "e229eb061b3f072a132c4b31bbc2fdb0" "site/built/09-vectorization.md" "2024-11-19" +"episodes/10-functions.Rmd" "14edd4cf50edb8fefeb987a17d740e1a" "site/built/10-functions.md" "2024-11-19" +"episodes/11-writing-data.Rmd" "8b26e062dddd2394d00c6847ff0b7505" "site/built/11-writing-data.md" "2024-11-19" +"episodes/12-dplyr.Rmd" "99b53f3fcaf96a394b950f19f4d5e118" "site/built/12-dplyr.md" "2024-11-19" +"episodes/13-tidyr.Rmd" "1c59c3bea4cec5e0c47654a546294f07" "site/built/13-tidyr.md" "2024-11-19" +"episodes/14-knitr-markdown.Rmd" "0c63ce92263a32f19fbec9f7b619b682" "site/built/14-knitr-markdown.md" "2024-11-19" +"episodes/15-wrap-up.Rmd" "c5ce0d34a37b7a99624ad1d6ac482256" "site/built/15-wrap-up.md" "2024-11-19" +"instructors/instructor-notes.md" "e61e7587564a6c4c11dbb6beea127764" "site/built/instructor-notes.md" "2024-11-19" +"learners/discuss.md" "42ad66ab1907e030914dbb2a94376a47" "site/built/discuss.md" "2024-11-19" +"learners/reference.md" "1cd851cc85adc26ea172da91e8c564f7" "site/built/reference.md" "2024-11-19" +"learners/setup.md" "f888f8a54b071715c0cf56896e650c00" "site/built/setup.md" "2024-11-19" +"profiles/learner-profiles.md" "60b93493cf1da06dfd63255d73854461" "site/built/learner-profiles.md" "2024-11-19" +"renv/profiles/lesson-requirements/renv.lock" "d4a067fadca2975fc084ccfca6bdae6c" "site/built/renv.lock" "2024-11-19" diff --git a/reference.md b/reference.md new file mode 100644 index 000000000..186affe03 --- /dev/null +++ b/reference.md @@ -0,0 +1,344 @@ +--- +title: 'Reference' +--- + +## Reference + +## [Introduction to R and RStudio](episodes/01-rstudio-intro.Rmd) + +- Use the escape key to cancel incomplete commands or running code + (Ctrl+C) if you're using R from the shell. +- Basic arithmetic operations follow standard order of precedence: + - Brackets: `(`, `)` + - Exponents: `^` or `**` + - Divide: `/` + - Multiply: `*` + - Add: `+` + - Subtract: `-` +- Scientific notation is available, e.g: `2e-3` +- Anything to the right of a `#` is a comment, R will ignore this! +- Functions are denoted by `function_name()`. Expressions inside the + brackets are evaluated before being passed to the function, and + functions can be nested. +- Mathematical functions: `exp`, `sin`, `log`, `log10`, `log2` etc. +- Comparison operators: `<`, `<=`, `>`, `>=`, `==`, `!=` +- Use `all.equal` to compare numbers! +- `<-` is the assignment operator. Anything to the right is evaluate, then + stored in a variable named to the left. +- `ls` lists all variables and functions you've created +- `rm` can be used to remove them +- When assigning values to function arguments, you *must* use `=`. + +## [Project management with RStudio](episodes/02-project-intro.Rmd) + +- To create a new project, go to File -> New Project +- Install the `packrat` package to create self-contained projects +- `install.packages` to install packages from CRAN +- `library` to load a package into R +- `packrat::status` to check whether all packages referenced in your + scripts have been installed. + +## [Seeking help](episodes/03-seeking-help.Rmd) + +- To access help for a function type `?function_name` or `help(function_name)` +- Use quotes for special operators e.g. `?"+"` +- Use fuzzy search if you can't remember a name '??search\_term' +- [CRAN task views](https://cran.at.r-project.org/web/views) are a good starting point. +- [Stack Overflow](https://stackoverflow.com/) is a good place to get help with your code. + - `?dput` will dump data you are working from so others can load it easily. + - `sessionInfo()` will give details of your setup that others may need for debugging. + +## [Data structures](episodes/04-data-structures-part1.Rmd) + +Individual values in R must be one of 5 **data types**, multiple values can be grouped in **data structures**. + +**Data types** + +- `typeof(object)` gives information about an items data type. + +- There are 5 main data types: + + - `?numeric` real (decimal) numbers + - `?integer` whole numbers only + - `?character` text + - `?complex` complex numbers + - `?logical` TRUE or FALSE values + + **Special types:** + + - `?NA` missing values + - `?NaN` "not a number" for undefined values (e.g. `0/0`). + - `?Inf`, `-Inf` infinity. + - `?NULL` a data structure that doesn't exist + + `NA` can occur in any atomic vector. `NaN`, and `Inf` can only + occur in complex, integer or numeric type vectors. Atomic vectors + are the building blocks for all other data structures. A `NULL` value + will occur in place of an entire data structure (but can occur as list + elements). + +**Basic data structures in R:** + +- atomic `?vector` (can only contain one type) +- `?list` (containers for other objects) +- `?data.frame` two dimensional objects whose columns can contain different types of data +- `?matrix` two dimensional objects that can contain only one type of data. +- `?factor` vectors that contain predefined categorical data. +- `?array` multi-dimensional objects that can only contain one type of data + +Remember that matrices are really atomic vectors underneath the hood, and that +data.frames are really lists underneath the hood (this explains some of the weirder +behaviour of R). + +**[Vectors](episodes/04-data-structures-part1.Rmd)** + +- `?vector()` All items in a vector must be the same type. +- Items can be converted from one type to another using *coercion*. +- The concatenate function 'c()' will append items to a vector. +- `seq(from=0, to=1, by=1)` will create a sequence of numbers. +- Items in a vector can be named using the `names()` function. + +**[Factors](episodes/04-data-structures-part1.Rmd)** + +- `?factor()` Factors are a data structure designed to store categorical data. +- `levels()` shows the valid values that can be stored in a vector of type factor. + +**[Lists](episodes/04-data-structures-part1.Rmd)** + +- `?list()` Lists are a data structure designed to store data of different types. + +**[Matrices](episodes/04-data-structures-part1.Rmd)** + +- `?matrix()` Matrices are a data structure designed to store 2-dimensional data. + +**[Data Frames](episodes/05-data-structures-part2.Rmd)** + +- `?data.frame` is a key data structure. It is a `list` of `vectors`. +- `cbind()` will add a column (vector) to a data.frame. +- `rbind()` will add a row (list) to a data.frame. + +**Useful functions for querying data structures:** + +- `?str` structure, prints out a summary of the whole data structure +- `?typeof` tells you the type inside an atomic vector +- `?class` what is the data structure? +- `?head` print the first `n` elements (rows for two-dimensional objects) +- `?tail` print the last `n` elements (rows for two-dimensional objects) +- `?rownames`, `?colnames`, `?dimnames` retrieve or modify the row names + and column names of an object. +- `?names` retrieve or modify the names of an atomic vector or list (or + columns of a data.frame). +- `?length` get the number of elements in an atomic vector +- `?nrow`, `?ncol`, `?dim` get the dimensions of a n-dimensional object + (Won't work on atomic vectors or lists). + +## [Exploring Data Frames](episodes/05-data-structures-part2.Rmd) + +- `read.csv` to read in data in a regular structure + - `sep` argument to specify the separator + - "," for comma separated + - "\\t" for tab separated + - Other arguments: + - `header=TRUE` if there is a header row + +## [Subsetting data](episodes/06-data-subsetting.Rmd) + +- Elements can be accessed by: + + - Index + - Name + - Logical vectors + +- `[` single square brackets: + + - *extract* single elements or *subset* vectors + - e.g.`x[1]` extracts the first item from vector x. + - *extract* single elements of a list. The returned value will be another `list()`. + - *extract* columns from a data.frame + +- `[` with two arguments to: + + - *extract* rows and/or columns of + - matrices + - data.frames + - e.g. `x[1,2]` will extract the value in row 1, column 2. + - e.g. `x[2,:]` will extract the entire second column of values. + +- `[[` double square brackets to extract items from lists. + +- `$` to access columns or list elements by name + +- negative indices skip elements + +## [Control flow](episodes/07-control-flow.Rmd) + +- Use `if` condition to start a conditional statement, `else if` condition to provide + additional tests, and `else` to provide a default +- The bodies of the branches of conditional statements must be indented. +- Use `==` to test for equality. +- `%in%` will return a `TRUE`/`FALSE` indicating if there is a match between an element and a vector. +- `X && Y` is only true if both X and Y are `TRUE`. +- `X || Y` is true if either X or Y, or both, are `TRUE`. +- Zero is considered `FALSE`; all other numbers are considered `TRUE` +- Nest loops to operate on multi-dimensional data. + +## [Creating publication quality graphics](episodes/08-plot-ggplot2.Rmd) + +- figures can be created with the grammar of graphics: + - `library(ggplot2)` + - `ggplot` to create the base figure + - `aes`thetics specify the data axes, shape, color, and data size + - `geom`etry functions specify the type of plot, e.g. `point`, `line`, `density`, `box` + - `geom`etry functions also add statistical transforms, e.g. `geom_smooth` + - `scale` functions change the mapping from data to aesthetics + - `facet` functions stratify the figure into panels + - `aes`thetics apply to individual layers, or can be set for the whole plot + inside `ggplot`. + - `theme` functions change the overall look of the plot + - order of layers matters! + - `ggsave` to save a figure. + +## [Vectorization](episodes/09-vectorization.Rmd) + +- Most functions and operations apply to each element of a vector +- `*` applies element-wise to matrices +- `%*%` for true matrix multiplication +- `any()` will return `TRUE` if any element of a vector is `TRUE` +- `all()` will return `TRUE` if *all* elements of a vector are `TRUE` + +## [Functions explained](episodes/10-functions.Rmd) + +- `?"function"` +- Put code whose parameters change frequently in a function, then call it with + different parameter values to customize its behavior. +- The last line of a function is returned, or you can use `return` explicitly +- Any code written in the body of the function will preferably look for variables defined inside the function. +- Document Why, then What, then lastly How (if the code isn't self explanatory) + +## [Writing data](episodes/11-writing-data.Rmd) + +- `write.table` to write out objects in regular format +- set `quote=FALSE` so that text isn't wrapped in `"` marks + +## [Dataframe manipulation with dplyr](episodes/12-dplyr.Rmd) + +- `library(dplyr)` +- `?select` to extract variables by name. +- `?filter` return rows with matching conditions. +- `?group_by` group data by one of more variables. +- `?summarize` summarize multiple values to a single value. +- `?mutate` add new variables to a data.frame. +- Combine operations using the `?"%>%"` pipe operator. + +## [Dataframe manipulation with tidyr](episodes/13-tidyr.Rmd) + +- `library(tidyr)` +- `?pivot_longer` convert data from *wide* to *long* format. +- `?pivot_wider` convert data from *long* to *wide* format. +- `?separate` split a single value into multiple values. +- `?unite` merge multiple values into a single value. + +## [Producing reports with knitr](episodes/14-knitr-markdown.Rmd) + +- Value of reproducible reports +- Basics of Markdown +- R code chunks +- Chunk options +- Inline R code +- Other output formats + +## [Best practices for writing good code](episodes/15-wrap-up.Rmd) + +- Program defensively, i.e., assume that errors are going to arise, and write code to detect them when they do. +- Write tests before writing code in order to help determine exactly what that code is supposed to do. +- Know what code is supposed to do before trying to debug it. +- Make it fail every time. +- Make it fail fast. +- Change one thing at a time, and for a reason. +- Keep track of what you've done. +- Be humble + +## Glossary + +[argument]{#argument} +: A value given to a function or program when it runs. +The term is often used interchangeably (and inconsistently) with [parameter](#parameter). + +[assign]{#assign} +: To give a value a name by associating a variable with it. + +[body]{#body} +: (of a function): the statements that are executed when a function runs. + +[comment]{#comment} +: A remark in a program that is intended to help human readers understand what is going on, +but is ignored by the computer. +Comments in Python, R, and the Unix shell start with a `#` character and run to the end of the line; +comments in SQL start with `--`, +and other languages have other conventions. + +[comma-separated values]{#comma-separated-values} +: (CSV) A common textual representation for tables +in which the values in each row are separated by commas. + +[delimiter]{#delimiter} +: A character or characters used to separate individual values, +such as the commas between columns in a [CSV](#comma-separated-values) file. + +[documentation]{#documentation} +: Human-language text written to explain what software does, +how it works, or how to use it. + +[floating-point number]{#floating-point-number} +: A number containing a fractional part and an exponent. +See also: [integer](#integer). + +[for loop]{#for-loop} +: A loop that is executed once for each value in some kind of set, list, or range. +See also: [while loop](#while-loop). + +[index]{#index} +: A subscript that specifies the location of a single value in a collection, +such as a single pixel in an image. + +[integer]{#integer} +: A whole number, such as -12343. See also: [floating-point number](#floating-point-number). + +[library]{#library} +: In R, the directory(ies) where [packages](#package) are stored. + +[package]{#package} +: A collection of R functions, data and compiled code in a well-defined format. Packages are stored in a [library](#library) and loaded using the library() function. + +[parameter]{#parameter} +: A variable named in the function's declaration that is used to hold a value passed into the call. +The term is often used interchangeably (and inconsistently) with [argument](#argument). + +[return statement]{#return-statement} +: A statement that causes a function to stop executing and return a value to its caller immediately. + +[sequence]{#sequence} +: A collection of information that is presented in a specific order. + +[shape]{#shape} +: An array's dimensions, represented as a vector. +For example, a 5×3 array's shape is `(5,3)`. + +[string]{#string} +: Short for "character string", +a [sequence](#sequence) of zero or more characters. + +[syntax error]{#syntax-error} +: A programming error that occurs when statements are in an order or contain characters +not expected by the programming language. + +[type]{#type} +: The classification of something in a program (for example, the contents of a variable) +as a kind of number (e.g. [floating-point number](#floating-point-number), [integer](#integer)), [string](#string), +or something else. In R the command typeof() is used to query a variables type. + +[while loop]{#while-loop} +: A loop that keeps executing as long as some condition is true. +See also: [for loop](#for-loop). + + diff --git a/renv.lock b/renv.lock new file mode 100644 index 000000000..8f35e8965 --- /dev/null +++ b/renv.lock @@ -0,0 +1,1022 @@ +{ + "R": { + "Version": "4.4.2", + "Repositories": [ + { + "Name": "carpentries", + "URL": "https://carpentries.r-universe.dev" + }, + { + "Name": "carpentries_archive", + "URL": "https://carpentries.github.io/drat" + }, + { + "Name": "CRAN", + "URL": "https://cran.rstudio.com" + } + ] + }, + "Packages": { + "DiagrammeR": { + "Package": "DiagrammeR", + "Version": "1.0.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "RColorBrewer", + "cli", + "dplyr", + "glue", + "htmltools", + "htmlwidgets", + "igraph", + "magrittr", + "purrr", + "readr", + "rlang", + "rstudioapi", + "scales", + "stringr", + "tibble", + "tidyr", + "viridisLite", + "visNetwork" + ], + "Hash": "584c1e1cbb6f9b6c3b0f4ef0ad960966" + }, + "MASS": { + "Package": "MASS", + "Version": "7.3-61", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats", + "utils" + ], + "Hash": "0cafd6f0500e5deba33be22c46bf6055" + }, + "Matrix": { + "Package": "Matrix", + "Version": "1.7-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "lattice", + "methods", + "stats", + "utils" + ], + "Hash": "5122bb14d8736372411f955e1b16bc8a" + }, + "R6": { + "Package": "R6", + "Version": "2.5.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "470851b6d5d0ac559e9d01bb352b4021" + }, + "RColorBrewer": { + "Package": "RColorBrewer", + "Version": "1.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "45f0398006e83a5b10b72a90663d8d8c" + }, + "base64enc": { + "Package": "base64enc", + "Version": "0.1-3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "543776ae6848fde2f48ff3816d0628bc" + }, + "bit": { + "Package": "bit", + "Version": "4.5.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "5dc7b2677d65d0e874fc4aaf0e879987" + }, + "bit64": { + "Package": "bit64", + "Version": "4.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bit", + "methods", + "stats", + "utils" + ], + "Hash": "e84984bf5f12a18628d9a02322128dfd" + }, + "bslib": { + "Package": "bslib", + "Version": "0.8.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "cachem", + "fastmap", + "grDevices", + "htmltools", + "jquerylib", + "jsonlite", + "lifecycle", + "memoise", + "mime", + "rlang", + "sass" + ], + "Hash": "b299c6741ca9746fb227debcb0f9fb6c" + }, + "cachem": { + "Package": "cachem", + "Version": "1.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "fastmap", + "rlang" + ], + "Hash": "cd9a672193789068eb5a2aad65a0dedf" + }, + "cli": { + "Package": "cli", + "Version": "3.6.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "b21916dd77a27642b447374a5d30ecf3" + }, + "clipr": { + "Package": "clipr", + "Version": "0.8.0", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "utils" + ], + "Hash": "3f038e5ac7f41d4ac41ce658c85e3042" + }, + "colorspace": { + "Package": "colorspace", + "Version": "2.1-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats" + ], + "Hash": "d954cb1c57e8d8b756165d7ba18aa55a" + }, + "cpp11": { + "Package": "cpp11", + "Version": "0.5.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "91570bba75d0c9d3f1040c835cee8fba" + }, + "crayon": { + "Package": "crayon", + "Version": "1.5.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "methods", + "utils" + ], + "Hash": "859d96e65ef198fd43e82b9628d593ef" + }, + "digest": { + "Package": "digest", + "Version": "0.6.37", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "33698c4b3127fc9f506654607fb73676" + }, + "dplyr": { + "Package": "dplyr", + "Version": "1.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "cli", + "generics", + "glue", + "lifecycle", + "magrittr", + "methods", + "pillar", + "rlang", + "tibble", + "tidyselect", + "utils", + "vctrs" + ], + "Hash": "fedd9d00c2944ff00a0e2696ccf048ec" + }, + "evaluate": { + "Package": "evaluate", + "Version": "1.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "3fd29944b231036ad67c3edb32e02201" + }, + "fansi": { + "Package": "fansi", + "Version": "1.0.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "utils" + ], + "Hash": "962174cf2aeb5b9eea581522286a911f" + }, + "farver": { + "Package": "farver", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "680887028577f3fa2a81e410ed0d6e42" + }, + "fastmap": { + "Package": "fastmap", + "Version": "1.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "aa5e1cd11c2d15497494c5292d7ffcc8" + }, + "fontawesome": { + "Package": "fontawesome", + "Version": "0.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "htmltools", + "rlang" + ], + "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" + }, + "fs": { + "Package": "fs", + "Version": "1.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "7f48af39fa27711ea5fbd183b399920d" + }, + "generics": { + "Package": "generics", + "Version": "0.1.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "methods" + ], + "Hash": "15e9634c0fcd294799e9b2e929ed1b86" + }, + "ggplot2": { + "Package": "ggplot2", + "Version": "3.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "R", + "cli", + "glue", + "grDevices", + "grid", + "gtable", + "isoband", + "lifecycle", + "mgcv", + "rlang", + "scales", + "stats", + "tibble", + "vctrs", + "withr" + ], + "Hash": "44c6a2f8202d5b7e878ea274b1092426" + }, + "glue": { + "Package": "glue", + "Version": "1.8.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "5899f1eaa825580172bb56c08266f37c" + }, + "gtable": { + "Package": "gtable", + "Version": "0.3.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "grid", + "lifecycle", + "rlang", + "stats" + ], + "Hash": "de949855009e2d4d0e52a844e30617ae" + }, + "highr": { + "Package": "highr", + "Version": "0.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "xfun" + ], + "Hash": "d65ba49117ca223614f71b60d85b8ab7" + }, + "hms": { + "Package": "hms", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "lifecycle", + "methods", + "pkgconfig", + "rlang", + "vctrs" + ], + "Hash": "b59377caa7ed00fa41808342002138f9" + }, + "htmltools": { + "Package": "htmltools", + "Version": "0.5.8.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "digest", + "fastmap", + "grDevices", + "rlang", + "utils" + ], + "Hash": "81d371a9cc60640e74e4ab6ac46dcedc" + }, + "htmlwidgets": { + "Package": "htmlwidgets", + "Version": "1.6.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "htmltools", + "jsonlite", + "knitr", + "rmarkdown", + "yaml" + ], + "Hash": "04291cc45198225444a397606810ac37" + }, + "igraph": { + "Package": "igraph", + "Version": "2.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "cli", + "cpp11", + "grDevices", + "graphics", + "lifecycle", + "magrittr", + "methods", + "pkgconfig", + "rlang", + "stats", + "utils", + "vctrs" + ], + "Hash": "c03878b48737a0e2da3b772d7b2e22da" + }, + "isoband": { + "Package": "isoband", + "Version": "0.2.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grid", + "utils" + ], + "Hash": "0080607b4a1a7b28979aecef976d8bc2" + }, + "jquerylib": { + "Package": "jquerylib", + "Version": "0.1.4", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "htmltools" + ], + "Hash": "5aab57a3bd297eee1c1d862735972182" + }, + "jsonlite": { + "Package": "jsonlite", + "Version": "1.8.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods" + ], + "Hash": "4e993b65c2c3ffbffce7bb3e2c6f832b" + }, + "knitr": { + "Package": "knitr", + "Version": "1.48", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "evaluate", + "highr", + "methods", + "tools", + "xfun", + "yaml" + ], + "Hash": "acf380f300c721da9fde7df115a5f86f" + }, + "labeling": { + "Package": "labeling", + "Version": "0.4.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "graphics", + "stats" + ], + "Hash": "b64ec208ac5bc1852b285f665d6368b3" + }, + "lattice": { + "Package": "lattice", + "Version": "0.22-6", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "stats", + "utils" + ], + "Hash": "cc5ac1ba4c238c7ca9fa6a87ca11a7e2" + }, + "lifecycle": { + "Package": "lifecycle", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "rlang" + ], + "Hash": "b8552d117e1b808b09a832f589b79035" + }, + "magrittr": { + "Package": "magrittr", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "7ce2733a9826b3aeb1775d56fd305472" + }, + "memoise": { + "Package": "memoise", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "cachem", + "rlang" + ], + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + }, + "mgcv": { + "Package": "mgcv", + "Version": "1.9-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "graphics", + "methods", + "nlme", + "splines", + "stats", + "utils" + ], + "Hash": "110ee9d83b496279960e162ac97764ce" + }, + "mime": { + "Package": "mime", + "Version": "0.12", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "tools" + ], + "Hash": "18e9c28c1d3ca1560ce30658b22ce104" + }, + "munsell": { + "Package": "munsell", + "Version": "0.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "colorspace", + "methods" + ], + "Hash": "4fd8900853b746af55b81fda99da7695" + }, + "nlme": { + "Package": "nlme", + "Version": "3.1-166", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "graphics", + "lattice", + "stats", + "utils" + ], + "Hash": "ccbb8846be320b627e6aa2b4616a2ded" + }, + "pillar": { + "Package": "pillar", + "Version": "1.9.0", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "cli", + "fansi", + "glue", + "lifecycle", + "rlang", + "utf8", + "utils", + "vctrs" + ], + "Hash": "15da5a8412f317beeee6175fbc76f4bb" + }, + "pkgconfig": { + "Package": "pkgconfig", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "utils" + ], + "Hash": "01f28d4278f15c76cddbea05899c5d6f" + }, + "prettyunits": { + "Package": "prettyunits", + "Version": "1.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "6b01fc98b1e86c4f705ce9dcfd2f57c7" + }, + "progress": { + "Package": "progress", + "Version": "1.2.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "crayon", + "hms", + "prettyunits" + ], + "Hash": "f4625e061cb2865f111b47ff163a5ca6" + }, + "purrr": { + "Package": "purrr", + "Version": "1.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "lifecycle", + "magrittr", + "rlang", + "vctrs" + ], + "Hash": "1cba04a4e9414bdefc9dcaa99649a8dc" + }, + "rappdirs": { + "Package": "rappdirs", + "Version": "0.3.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" + }, + "readr": { + "Package": "readr", + "Version": "2.1.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "cli", + "clipr", + "cpp11", + "crayon", + "hms", + "lifecycle", + "methods", + "rlang", + "tibble", + "tzdb", + "utils", + "vroom" + ], + "Hash": "9de96463d2117f6ac49980577939dfb3" + }, + "renv": { + "Package": "renv", + "Version": "1.0.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "47623f66b4e80b3b0587bc5d7b309888" + }, + "rlang": { + "Package": "rlang", + "Version": "1.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "3eec01f8b1dee337674b2e34ab1f9bc1" + }, + "rmarkdown": { + "Package": "rmarkdown", + "Version": "2.29", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bslib", + "evaluate", + "fontawesome", + "htmltools", + "jquerylib", + "jsonlite", + "knitr", + "methods", + "tinytex", + "tools", + "utils", + "xfun", + "yaml" + ], + "Hash": "df99277f63d01c34e95e3d2f06a79736" + }, + "rstudioapi": { + "Package": "rstudioapi", + "Version": "0.17.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "5f90cd73946d706cfe26024294236113" + }, + "sass": { + "Package": "sass", + "Version": "0.4.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R6", + "fs", + "htmltools", + "rappdirs", + "rlang" + ], + "Hash": "d53dbfddf695303ea4ad66f86e99b95d" + }, + "scales": { + "Package": "scales", + "Version": "1.3.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "RColorBrewer", + "cli", + "farver", + "glue", + "labeling", + "lifecycle", + "munsell", + "rlang", + "viridisLite" + ], + "Hash": "c19df082ba346b0ffa6f833e92de34d1" + }, + "stringi": { + "Package": "stringi", + "Version": "1.8.4", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "stats", + "tools", + "utils" + ], + "Hash": "39e1144fd75428983dc3f63aa53dfa91" + }, + "stringr": { + "Package": "stringr", + "Version": "1.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "magrittr", + "rlang", + "stringi", + "vctrs" + ], + "Hash": "960e2ae9e09656611e0b8214ad543207" + }, + "tibble": { + "Package": "tibble", + "Version": "3.2.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "fansi", + "lifecycle", + "magrittr", + "methods", + "pillar", + "pkgconfig", + "rlang", + "utils", + "vctrs" + ], + "Hash": "a84e2cc86d07289b3b6f5069df7a004c" + }, + "tidyr": { + "Package": "tidyr", + "Version": "1.3.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "cpp11", + "dplyr", + "glue", + "lifecycle", + "magrittr", + "purrr", + "rlang", + "stringr", + "tibble", + "tidyselect", + "utils", + "vctrs" + ], + "Hash": "915fb7ce036c22a6a33b5a8adb712eb1" + }, + "tidyselect": { + "Package": "tidyselect", + "Version": "1.2.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "rlang", + "vctrs", + "withr" + ], + "Hash": "829f27b9c4919c16b593794a6344d6c0" + }, + "tinytex": { + "Package": "tinytex", + "Version": "0.54", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "xfun" + ], + "Hash": "3ec7e3ddcacc2d34a9046941222bf94d" + }, + "tzdb": { + "Package": "tzdb", + "Version": "0.4.0", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "cpp11" + ], + "Hash": "f561504ec2897f4d46f0c7657e488ae1" + }, + "utf8": { + "Package": "utf8", + "Version": "1.2.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "62b65c52671e6665f803ff02954446e9" + }, + "vctrs": { + "Package": "vctrs", + "Version": "0.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "rlang" + ], + "Hash": "c03fa420630029418f7e6da3667aac4a" + }, + "viridisLite": { + "Package": "viridisLite", + "Version": "0.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "c826c7c4241b6fc89ff55aaea3fa7491" + }, + "visNetwork": { + "Package": "visNetwork", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "htmltools", + "htmlwidgets", + "jsonlite", + "magrittr", + "methods", + "stats", + "utils" + ], + "Hash": "3e48b097e8d9a91ecced2ed4817a678d" + }, + "vroom": { + "Package": "vroom", + "Version": "1.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bit64", + "cli", + "cpp11", + "crayon", + "glue", + "hms", + "lifecycle", + "methods", + "progress", + "rlang", + "stats", + "tibble", + "tidyselect", + "tzdb", + "vctrs", + "withr" + ], + "Hash": "390f9315bc0025be03012054103d227c" + }, + "withr": { + "Package": "withr", + "Version": "3.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics" + ], + "Hash": "cc2d62c76458d425210d1eb1478b30b4" + }, + "xfun": { + "Package": "xfun", + "Version": "0.49", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "stats", + "tools" + ], + "Hash": "8687398773806cfff9401a2feca96298" + }, + "yaml": { + "Package": "yaml", + "Version": "2.3.10", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "51dab85c6c98e50a18d7551e9d49f76c" + } + } +} diff --git a/results/lifeExp.png b/results/lifeExp.png new file mode 100644 index 000000000..fb1730b8f Binary files /dev/null and b/results/lifeExp.png differ diff --git a/setup.md b/setup.md new file mode 100644 index 000000000..1e9a9654d --- /dev/null +++ b/setup.md @@ -0,0 +1,10 @@ +--- +title: Setup +--- + +This lesson assumes you have R and RStudio installed on your computer. + +- [Download and install the latest version of R](https://www.r-project.org/). +- [Download and install RStudio](https://www.rstudio.com/products/rstudio/download/#download). RStudio is an application (an integrated development environment or IDE) that facilitates the use of R and offers a number of nice additional features. You will need the free Desktop version for your computer. + +