Created
January 11, 2016 18:20
-
-
Save airstrike/eb3e72129a5e94403bf1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| country <- c("Brazil", "Russia", "India", "China") | |
| pop.thousands <- c(202679, 146300, 1275921, 1367820) | |
| economies <- cbind(country, pop.thousands) # add populaton | |
| gdp.millions <- c(2346583, 1860598, 2051228, 10356508) | |
| economies <- cbind(economies, gdp.millions) # add gdp in millions | |
| rownames(economies) <- economies[ ,"country"] # store country name in row names | |
| economies <- economies[, -1] # drop the variable "country" | |
| class(economies) <- "numeric" # change matrix to numeric | |
| economies[, 1] <- economies[, 1] / 1000 # change population units to millions | |
| colnames(economies) <- c("pop.millions", "gdp.millions") # change column names | |
| gdp.per.capita <- economies[, 2] / economies[, 1] # create gdp.per.capita vector | |
| economies <- cbind(economies, gdp.per.capita) # add gdp.per.capita to matrix | |
| print(colMeans(economies)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment