Created
November 15, 2015 20:10
-
-
Save davidcomfort/2ae530c03bd0fd9bc161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load reshape2 package | |
library(reshape2) | |
# reshape gdp_per_capita data frame | |
gdp_per_capita <- melt(gdp_per_capita, id.vars="Country", variable.name = "Years", value.name="GDP per capita", na.rm = TRUE) | |
str(gdp_per_capita) | |
## 'data.frame': 43252 obs. of 3 variables: | |
## $ Country : chr "Afghanistan" "Albania" "Algeria" "Andorra" ... | |
## $ Years : Factor w/ 214 levels "1800","1801",..: 1 1 1 1 1 1 1 1 1 1 ... | |
## $ GDP per capita: num 634 861 1360 1260 650 ... | |
# change factor to numeric | |
gdp_per_capita$Years <- as.numeric(as.character(gdp_per_capita$Years)) | |
str(gdp_per_capita) | |
## 'data.frame': 43252 obs. of 3 variables: | |
## $ Country : chr "Afghanistan" "Albania" "Algeria" "Andorra" ... | |
## $ Years : num 1800 1800 1800 1800 1800 1800 1800 1800 1800 1800 ... | |
## $ GDP per capita: num 634 861 1360 1260 650 ... | |
head(gdp_per_capita) | |
## Country Years GDP per capita | |
## 2 Afghanistan 1800 634.4000 | |
## 4 Albania 1800 860.5880 | |
## 5 Algeria 1800 1360.0000 | |
## 7 Andorra 1800 1260.0000 | |
## 8 Angola 1800 650.0000 | |
## 10 Antigua and Barbuda 1800 796.5934 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment