Please download the answer file and edit it on Rstudio. Write your student number in the correct place at the beginning of the answer file. When you finish, send the answers.R file to the answers’ mailbox. All questions are independent and can be answered in any order.

1 Lists and vectors

1.1 Write the R command to create a list called x, with two elements, called weight and group, with the values shown below. Then you must show the content of x. If everything is right, you should get something like this:

## $weight
##  [1] 4.17 5.18 4.50 5.17 5.33 4.81 4.41 5.87 6.03 4.32 6.31 5.54 5.37 4.92 5.80
## 
## $group
##  [1] ctrl ctrl ctrl ctrl ctrl trt1 trt1 trt1 trt1 trt1 trt2 trt2 trt2 trt2 trt2
## Levels: ctrl trt1 trt2
# replace all this line (including the `#` symbol) with your answer

1.2 Write the code to print all values on x$weights, except the third one.

##  [1] 4.17 5.18 5.17 5.33 4.81 4.41 5.87 6.03 4.32 6.31 5.54 5.37 4.92 5.80
# replace all this line (including the `#` symbol) with your answer

1.3 Write the code to print the mean of x$weight only for the cases where group is equal to "trt1".

## [1] 5.088
# replace all this line (including the `#` symbol) with your answer

1.4 Write the code to find the x$group of the element whose x$weight is equal to the median of all x$weight.

## [1] ctrl
## Levels: ctrl trt1 trt2
# replace all this line (including the `#` symbol) with your answer

2 Data frames

For this question we will use data about several countries evaluated in the year 2007. The homework Rmd document includes a data frame called world with columns representing some demographic values for each country. You do not need to write it again.

2.1 What are the variables? Write the command to show the column names of world.

## [1] "population" "continent"  "life_exp"
# replace all this line (including the `#` symbol) with your answer

2.2 How many countries are in the world?

Write the command to find how many lines are there in the world data frame

## [1] 142
# replace all this line (including the `#` symbol) with your answer

2.3 Write the command to show the first 5 lines of world.

##             population continent life_exp
## Afghanistan   31889923      Asia   43.828
## Albania        3600523    Europe   76.423
## Algeria       33333216    Africa   72.301
## Angola        12420476    Africa   42.731
## Argentina     40301927  Americas   75.320
# replace all this line (including the `#` symbol) with your answer

2.4 Write the command to show the data corresponding to Turkey

##        population continent life_exp
## Turkey   71158647    Europe   71.777
# replace all this line (including the `#` symbol) with your answer

2.5 How many countries are in each continent? Write the command to count the number of times that each value appears in the continent column.

## 
##   Africa Americas     Asia   Europe  Oceania 
##       52       25       33       30        2
# replace all this line (including the `#` symbol) with your answer

2.6 Which countries have population greater than 200 million people?

##               population continent life_exp
## China         1318683096      Asia   72.961
## India         1110396331      Asia   64.698
## Indonesia      223547000      Asia   70.650
## United States  301139947  Americas   78.242
# replace all this line (including the `#` symbol) with your answer

2.7 Write the command to create a data frame called Africa with all the rows of world where continent=='Africa'. Show the result of summary(Africa)

##    population           continent     life_exp    
##  Min.   :   199579   Africa  :52   Min.   :39.61  
##  1st Qu.:  2909226   Americas: 0   1st Qu.:47.83  
##  Median : 10093310   Asia    : 0   Median :52.93  
##  Mean   : 17875763   Europe  : 0   Mean   :54.81  
##  3rd Qu.: 19363654   Oceania : 0   3rd Qu.:59.44  
##  Max.   :135031164                 Max.   :76.44
# replace all this line (including the `#` symbol) with your answer

2.8 Which is the biggest population in Africa? Show the value of the maximum population.

## [1] 135031164
# replace all this line (including the `#` symbol) with your answer

2.9 Which is the African country with the biggest population? Show the row of the country which population is the maximum.

##         population continent life_exp
## Nigeria  135031164    Africa   46.859
# replace all this line (including the `#` symbol) with your answer

2.10 Which is the life expectancy of the African country with the smallest population? Show the life_exp column of the country which population is the minimum.

# replace all this line (including the `#` symbol) with your answer
## [1] 65.528