1) Create the vectors
#x,y,z
x<- c (5, 10, 15, 20, 25, 30)
y<- c (-1, NA, 75, 3, 5, 8)
z<- c (5)
2) Multiply
#multiplication by the z vector
x*z
## [1] 25 50 75 100 125 150
y*z
## [1] -5 NA 375 15 25 40
#creating new objects
p<- c (25, 50, 75, 100, 125, 150)
q<- c (-5, NA, 375, 15, 25, 40)
#printing new vectors
p
## [1] 25 50 75 100 125 150
q
## [1] -5 NA 375 15 25 40
3) Replace the missing element
#replacing the missing element of y vector
y<- c (-1, NA, 75, 3, 5, 8)
y<-ifelse(test = is.na(y)==T, yes = 2.5, no =y)
y
## [1] -1.0 2.5 75.0 3.0 5.0 8.0
#replacing the missing element of q vector (y vector after multiplying by z)
q<- c (-5, NA, 375, 15, 25, 40)
q<-ifelse(test = is.na(q)==T, yes = 2.5, no =q)
q
## [1] -5.0 2.5 375.0 15.0 25.0 40.0
4) PRB Data
## Parsed with column specification:
## cols(
## .default = col_integer(),
## Country = col_character(),
## Continent = col_character(),
## Region = col_character(),
## Population. = col_double(),
## Rate.of.natural.increase = col_double(),
## ProjectedPopMid2025 = col_double(),
## ProjectedPopMid2050 = col_double(),
## IMR = col_double(),
## TFR = col_double(),
## PercPop1549HIVAIDS2001 = col_double(),
## PercPop1549HIVAIDS2007 = col_double(),
## PercPpUnderNourished0204 = col_double(),
## PopDensPerSqMile = col_double()
## )
## See spec(...) for full column specifications.
#4.1firt 10 country names
head(prb$Country, 10)
## [1] "Afghanistan" "Albania" "Algeria"
## [4] "Andorra" "Angola" "Antigua and Barbuda"
## [7] "Argentina" "Armenia" "Australia"
## [10] "Austria"
#4.2how many countries
##1
summary(prb$Country)
## Length Class Mode
## 209 character character
##2
list(prb$Country)
## [[1]]
## [1] "Afghanistan" "Albania"
## [3] "Algeria" "Andorra"
## [5] "Angola" "Antigua and Barbuda"
## [7] "Argentina" "Armenia"
## [9] "Australia" "Austria"
## [11] "Azerbaijan" "Bahamas"
## [13] "Bahrain" "Bangladesh"
## [15] "Barbados" "Belarus"
## [17] "Belgium" "Belize"
## [19] "Benin" "Bhutan"
## [21] "Bolivia" "Bosnia-Herzegovina"
## [23] "Botswana" "Brazil"
## [25] "Brunei" "Bulgaria"
## [27] "Burkina Faso" "Burundi"
## [29] "Cambodia" "Cameroon"
## [31] "Canada" "Cape Verde"
## [33] "Central African Republic" "Chad"
## [35] "Channel Islands" "Chile"
## [37] "China" "China Hong Kong SARe"
## [39] "China Macao SARe" "Colombia"
## [41] "Comoros" "Congo"
## [43] "Congo Dem. Rep." "Costa Rica"
## [45] "C<U+FFFD>te d'Ivoire" "Croatia"
## [47] "Cuba" "Cyprus"
## [49] "Czech Republic" "Denmark"
## [51] "Djibouti" "Dominica"
## [53] "Dominican Republic" "Ecuador"
## [55] "Egypt" "El Salvador"
## [57] "Equatorial Guinea" "Eritrea"
## [59] "Estonia" "Ethiopia"
## [61] "Federated States of Micronesia" "Fiji"
## [63] "Finland" "France"
## [65] "French Guiana" "French Polynesia"
## [67] "Gabon" "Gambia"
## [69] "Georgia" "Germany"
## [71] "Ghana" "Greece"
## [73] "Grenada" "Guadeloupe"
## [75] "Guam" "Guatemala"
## [77] "Guinea" "Guinea-Bissau"
## [79] "Guyana" "Haiti"
## [81] "Honduras" "Hungary"
## [83] "Iceland" "India"
## [85] "Indonesia" "Iran"
## [87] "Iraq" "Ireland"
## [89] "Israel" "Italy"
## [91] "Jamaica" "Japan"
## [93] "Jordan" "Kazakhstan"
## [95] "Kenya" "Kiribati"
## [97] "Korea North" "Korea South"
## [99] "Kosovof" "Kuwait"
## [101] "Kyrgyzstan" "Laos"
## [103] "Latvia" "Lebanon"
## [105] "Lesotho" "Liberia"
## [107] "Libya" "Liechtenstein"
## [109] "Lithuania" "Luxembourg"
## [111] "Macedoniag" "Madagascar"
## [113] "Malawi" "Malaysia"
## [115] "Maldives" "Mali"
## [117] "Malta" "Marshall Islands"
## [119] "Martinique" "Mauritania"
## [121] "Mauritius" "Mayotte"
## [123] "Mexico" "Moldova"
## [125] "Monaco" "Mongolia"
## [127] "Montenegro" "Morocco"
## [129] "Mozambique" "Myanmar"
## [131] "Namibia" "Nauru"
## [133] "Nepal" "Netherlands"
## [135] "Netherlands Antilles" "New Caledonia"
## [137] "New Zealand" "Nicaragua"
## [139] "Niger" "Nigeria"
## [141] "Norway" "Oman"
## [143] "Pakistan" "Palau"
## [145] "Palestinian Territory" "Papua New Guinea"
## [147] "Paraguay" "Peru"
## [149] "Philippines" "Poland"
## [151] "Portugal" "Puerto Rico"
## [153] "Qatar" "Reunion"
## [155] "Romania" "Russia"
## [157] "Rwanda" "Saint Lucia"
## [159] "Samoa" "San Marino"
## [161] "Sao Tome and Principe" "Saudi Arabia"
## [163] "Senegal" "Serbia"
## [165] "Seychelles" "Sierra Leone"
## [167] "Singapore" "Slovakia"
## [169] "Slovenia" "Solomon Islands"
## [171] "Somalia" "Spain"
## [173] "Sri Lanka" "St. Kitts-Nevis"
## [175] "St. Vincent & the Grenadines" "Sudan"
## [177] "Suriname" "Swaziland"
## [179] "Switzerland" "Syria"
## [181] "Taiwan" "Tajikistan"
## [183] "Tanzania" "Thailand"
## [185] "Timor-Leste" "Togo"
## [187] "Tonga" "Trinidad and Tobago"
## [189] "Tunisia" "Turkey"
## [191] "Turkmenistan" "Tuvalu"
## [193] "Uganda" "Ukraine"
## [195] "United Arab Emirates" "United Kingdom"
## [197] "United States" "Uruguay"
## [199] "Uzbekistan" "Vanuatu"
## [201] "Venezuela" "Vietnam"
## [203] "Western Sahara" "Yemen"
## [205] "Zambia" "Zimbabwe"
## [207] "Panama" "South Africa"
## [209] "Sweden"
##3
str(prb$e0Total)
## int [1:209] 43 75 72 NA 43 73 75 71 81 80 ...
#4.3missing countries
prb$e0Total[is.na(prb$e0Total)]
## [1] NA NA
#4.4which countries are missing
list (prb$Country[is.na(prb$e0Total)])
## [[1]]
## [1] "Andorra" "Monaco"