--- author: "Write your name here" number: STUDENT_NUMBER title: "Homework 3" subtitle: "Computing in Molecular Biology and Genetics I. Istanbul University." date: "October 23, 2019" output: html_document: number_sections: yes self_contained: no --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) options(width=85) ``` # Lists and vectors ## 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: ```{r q1a} # replace all this line (including the `#` symbol) with your answer ``` ## Write the code to print all values on `x$weights`, except the third one. ```{r q1b} # replace all this line (including the `#` symbol) with your answer ``` ## Write the code to print the mean of `x$weight` **only** for the cases where `group` is equal to `"trt1"`. ```{r q1c} # replace all this line (including the `#` symbol) with your answer ``` ## Write the code to find the `x$group` of the element whose `x$weight` is equal to the median of all `x$weight`. ```{r q1d} # replace all this line (including the `#` symbol) with your answer ``` # 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. ```{r include=FALSE} world <- data.frame(population = c(31889923, 3600523, 33333216, 12420476, 40301927, 20434176, 8199783, 708573, 150448339, 10392226, 8078314, 9119152, 4552198, 1639131, 190010647, 7322858, 14326203, 8390505, 14131858, 17696293, 33390141, 4369038, 10238807, 16284741, 1318683096, 44227550, 710960, 64606759, 3800610, 4133884, 18013409, 4493312, 11416987, 10228744, 5468120, 496374, 9319622, 13755680, 80264543, 6939688, 551201, 4906585, 76511887, 5238460, 61083916, 1454867, 1688359, 82400996, 22873338, 10706290, 12572928, 9947814, 1472041, 8502814, 7483763, 6980412, 9956108, 301931, 1110396331, 223547000, 69453570, 27499638, 4109086, 6426679, 58147733, 2780132, 127467972, 6053193, 35610177, 23301725, 49044790, 2505559, 3921278, 2012649, 3193942, 6036914, 19167654, 13327079, 24821286, 12031795, 3270065, 1250882, 108700891, 2874127, 684736, 33757175, 19951656, 47761980, 2055080, 28901790, 16570613, 4115771, 5675356, 12894865, 135031164, 4627926, 3204897, 169270617, 3242173, 6667147, 28674757, 91077287, 38518241, 10642836, 3942491, 798094, 22276056, 8860588, 199579, 27601038, 12267493, 10150265, 6144562, 4553009, 5447502, 2009245, 9118773, 43997828, 40448191, 20378239, 42292929, 1133066, 9031088, 7554661, 19314747, 23174294, 38139640, 65068149, 5701579, 1056608, 10276158, 71158647, 29170398, 60776238, 301139947, 3447496, 26084662, 85262356, 4018332, 22211743, 11746035, 12311143), continent = c("Asia", "Europe", "Africa", "Africa", "Americas", "Oceania", "Europe", "Asia", "Asia", "Europe", "Africa", "Americas", "Europe", "Africa", "Americas", "Europe", "Africa", "Africa", "Asia", "Africa", "Americas", "Africa", "Africa", "Americas", "Asia", "Americas", "Africa", "Africa", "Africa", "Americas", "Africa", "Europe", "Americas", "Europe", "Europe", "Africa", "Americas", "Americas", "Africa", "Americas", "Africa", "Africa", "Africa", "Europe", "Europe", "Africa", "Africa", "Europe", "Africa", "Europe", "Americas", "Africa", "Africa", "Americas", "Americas", "Asia", "Europe", "Europe", "Asia", "Asia", "Asia", "Asia", "Europe", "Asia", "Europe", "Americas", "Asia", "Asia", "Africa", "Asia", "Asia", "Asia", "Asia", "Africa", "Africa", "Africa", "Africa", "Africa", "Asia", "Africa", "Africa", "Africa", "Americas", "Asia", "Europe", "Africa", "Africa", "Asia", "Africa", "Asia", "Europe", "Oceania", "Americas", "Africa", "Africa", "Europe", "Asia", "Asia", "Americas", "Americas", "Americas", "Asia", "Europe", "Europe", "Americas", "Africa", "Europe", "Africa", "Africa", "Asia", "Africa", "Europe", "Africa", "Asia", "Europe", "Europe", "Africa", "Africa", "Europe", "Asia", "Africa", "Africa", "Europe", "Europe", "Asia", "Asia", "Africa", "Asia", "Africa", "Americas", "Africa", "Europe", "Africa", "Europe", "Americas", "Americas", "Americas", "Asia", "Asia", "Asia", "Africa", "Africa"), life_exp = c(43.828, 76.423, 72.301, 42.731, 75.32, 81.235, 79.829, 75.635, 64.062, 79.441, 56.728, 65.554, 74.852, 50.728, 72.39, 73.005, 52.295, 49.58, 59.723, 50.43, 80.653, 44.741, 50.651, 78.553, 72.961, 72.889, 65.152, 46.462, 55.322, 78.782, 48.328, 75.748, 78.273, 76.486, 78.332, 54.791, 72.235, 74.994, 71.338, 71.878, 51.579, 58.04, 52.947, 79.313, 80.657, 56.735, 59.448, 79.406, 60.022, 79.483, 70.259, 56.007, 46.388, 60.916, 70.198, 82.208, 73.338, 81.757, 64.698, 70.65, 70.964, 59.545, 78.885, 80.745, 80.546, 72.567, 82.603, 72.535, 54.11, 67.297, 78.623, 77.588, 71.993, 42.592, 45.678, 73.952, 59.443, 48.303, 74.241, 54.467, 64.164, 72.801, 76.195, 66.803, 74.543, 71.164, 42.082, 62.069, 52.906, 63.785, 79.762, 80.204, 72.899, 56.867, 46.859, 80.196, 75.64, 65.483, 75.537, 71.752, 71.421, 71.688, 75.563, 78.098, 78.746, 76.442, 72.476, 46.242, 65.528, 72.777, 63.062, 74.002, 42.568, 79.972, 74.663, 77.926, 48.159, 49.339, 80.941, 72.396, 58.556, 39.613, 80.884, 81.701, 74.143, 78.4, 52.517, 70.616, 58.42, 69.819, 73.923, 71.777, 51.542, 79.425, 78.242, 76.384, 73.747, 74.249, 73.422, 62.698, 42.384, 43.487), row.names = c("Afghanistan", "Albania", "Algeria", "Angola", "Argentina", "Australia", "Austria", "Bahrain", "Bangladesh", "Belgium", "Benin", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.", "Congo, Rep.", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Czech Republic", "Denmark", "Djibouti", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Ethiopia", "Finland", "France", "Gabon", "Gambia", "Germany", "Ghana", "Greece", "Guatemala", "Guinea", "Guinea-Bissau", "Haiti", "Honduras", "Hong Kong, China", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kenya", "Korea, Dem. Rep.", "Korea, Rep.", "Kuwait", "Lebanon", "Lesotho", "Liberia", "Libya", "Madagascar", "Malawi", "Malaysia", "Mali", "Mauritania", "Mauritius", "Mexico", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Reunion", "Romania", "Rwanda", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tanzania", "Thailand", "Togo", "Trinidad and Tobago", "Tunisia", "Turkey", "Uganda", "United Kingdom", "United States", "Uruguay", "Venezuela", "Vietnam", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe")) ``` ## What are the variables? Write the command to show the column names of `world`. ```{r q2a} # replace all this line (including the `#` symbol) with your answer ``` ## How many countries are in the world? Write the command to find how many lines are there in the `world` data frame ```{r q2b} # replace all this line (including the `#` symbol) with your answer ``` ## Write the command to show the first 5 lines of `world`. ```{r q2c} # replace all this line (including the `#` symbol) with your answer ``` ## Write the command to show the data corresponding to Turkey ```{r q2d} # replace all this line (including the `#` symbol) with your answer ``` ## How many countries are in each continent? Write the command to count the number of times that each value appears in the `continent` column. ```{r q2e} # replace all this line (including the `#` symbol) with your answer ``` ## Which countries have population greater than 200 million people? ```{r q2f} # replace all this line (including the `#` symbol) with your answer ``` ## 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)` ```{r q2g} # replace all this line (including the `#` symbol) with your answer ``` ## Which is the biggest population in Africa? Show the value of the maximum population. ```{r q2h} # replace all this line (including the `#` symbol) with your answer ``` ## Which is the African country with the biggest population? Show the row of the country which population is the maximum. ```{r q2i} # replace all this line (including the `#` symbol) with your answer ``` ## 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. ```{r q2j} # replace all this line (including the `#` symbol) with your answer ```