Question 1

url <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"
data <- read.csv(url)
agricultureLogical <- data$ACR == 3 & data$AGS == 6
which(agricultureLogical)[1:3]
## [1] 125 238 262

Question 2

library(jpeg)
url <- "http://d396qusza40orc.cloudfront.net/getdata%2Fjeff.jpg"
download.file(url, "Q3/jeff.jpeg")
data <- readJPEG("Q3/jeff.jpeg", native = TRUE)
round(quantile(data, probs = c(0.3, 0.8)))
##       30%       80% 
## -15259150 -10575416

Question 3

url_1 <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FGDP.csv"
url_2 <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FEDSTATS_Country.csv"
data_1 <- read.csv(url_1)
data_2 <- read.csv(url_2)
data_1 <- data_1[,1:2]
names(data_1) <- c("GDP", "rank")
data_1$rank <- as.numeric(as.character(data_1$rank))
## Warning: NAs introduced by coercion
data_1 <- data_1[complete.cases(data_1),]
data_1 <- data_1[order(data_1$rank, decreasing = TRUE), ]
merged_data <- merge(data_1, data_2, by.x = "GDP", by.y = "CountryCode", sort = FALSE)

nrow(merged_data)
## [1] 189
merged_data$Long.Name[13]
## [1] St. Kitts and Nevis
## 234 Levels: American Samoa Antigua and Barbuda ... World

Question 4

tapply(merged_data$rank, merged_data$Income.Group, mean)
##                         High income: OECD High income: nonOECD 
##                   NA             32.96667             91.91304 
##           Low income  Lower middle income  Upper middle income 
##            133.72973            107.70370             92.13333

Question 5

library(Hmisc)
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## 
## Attaching package: 'Hmisc'
## 
## The following objects are masked from 'package:base':
## 
##     format.pval, round.POSIXt, trunc.POSIXt, units
cuttedRank <- cut2(merged_data$rank, g=5)
table(merged_data$Income.Group, cuttedRank)
##                       cuttedRank
##                        [  1, 39) [ 39, 77) [ 77,115) [115,154) [154,190]
##                                0         0         0         0         0
##   High income: OECD           18        10         1         1         0
##   High income: nonOECD         4         5         8         5         1
##   Low income                   0         1         9        16        11
##   Lower middle income          5        13        12         8        16
##   Upper middle income         11         9         8         8         9