Assigning vectors of numbers to x, y, and z
x <- c(5,10,15,20,25)
y <- c(-1,NA,75,3,5,8)
z <- 5
Multiplying vectors x and y by z
a <- x*z
b <- y*z
print(a)
## [1] 25 50 75 100 125
print(b)
## [1] -5 NA 375 15 25 40
Replacing the missing element of y vector with 2.5
y <- ifelse(is.na(y)==T, 2.5, y)
print(y)
## [1] -1.0 2.5 75.0 3.0 5.0 8.0
Loading PRB data from github
prb <- read_csv(file = "https://raw.githubusercontent.com/coreysparks/data/master/PRB2008_All.csv")
## 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.
Printing the first 10 country names
head(prb$Country, 10)
## [1] "Afghanistan" "Albania" "Algeria"
## [4] "Andorra" "Angola" "Antigua and Barbuda"
## [7] "Argentina" "Armenia" "Australia"
## [10] "Austria"
Identifying the number of countries in the data
str(prb$Country)
## chr [1:209] "Afghanistan" "Albania" "Algeria" "Andorra" "Angola" ...
describe(prb)
## Warning in min(diff(sort(unique(xnum)))): no non-missing arguments to min;
## returning Inf
## prb
##
## 35 Variables 209 Observations
## ---------------------------------------------------------------------------
## Y
## n missing distinct Info Mean Gmd .05 .10
## 209 0 209 1 105 70 11.4 21.8
## .25 .50 .75 .90 .95
## 53.0 105.0 157.0 188.2 198.6
##
## lowest : 1 2 3 4 5, highest: 205 206 207 208 209
## ---------------------------------------------------------------------------
## X
## n missing distinct Info Mean Gmd .05 .10
## 209 0 209 1 105 70 11.4 21.8
## .25 .50 .75 .90 .95
## 53.0 105.0 157.0 188.2 198.6
##
## lowest : 1 2 3 4 5, highest: 205 206 207 208 209
## ---------------------------------------------------------------------------
## ID
## n missing distinct Info Mean Gmd .05 .10
## 209 0 208 1 105.2 70.45 11.4 21.8
## .25 .50 .75 .90 .95
## 53.0 104.0 158.0 189.2 199.6
##
## lowest : 1 2 3 4 5, highest: 206 207 208 209 210
## ---------------------------------------------------------------------------
## Country
## n missing distinct
## 209 0 209
##
## lowest : Afghanistan Albania Algeria Andorra Angola
## highest: Vietnam Western Sahara Yemen Zambia Zimbabwe
## ---------------------------------------------------------------------------
## Continent
## n missing distinct
## 209 0 6
##
## Value Africa Asia Europe North America
## Frequency 56 51 45 27
## Proportion 0.268 0.244 0.215 0.129
##
## Value Oceania South America
## Frequency 17 13
## Proportion 0.081 0.062
## ---------------------------------------------------------------------------
## Region
## n missing distinct
## 209 0 18
##
## lowest : Carribean Central America East Asia EASTERN AFRICA Eastern Europe
## highest: SOUTHERN AFRICA Southern Europe WESTERN AFRICA Western Asia Western Europe
## ---------------------------------------------------------------------------
## Year
## n missing distinct Info Mean Gmd
## 209 0 1 0 2008 0
##
## Value 2008
## Frequency 209
## Proportion 1
## ---------------------------------------------------------------------------
## Population.
## n missing distinct Info Mean Gmd .05 .10
## 209 0 142 1 32.08 52.57 0.10 0.20
## .25 .50 .75 .90 .95
## 0.90 5.90 20.70 61.44 100.82
##
## Value 0 10 20 30 40 50 60 70 80 90
## Frequency 96 50 17 12 6 5 3 5 2 2
## Proportion 0.459 0.239 0.081 0.057 0.029 0.024 0.014 0.024 0.010 0.010
##
## Value 110 130 140 150 170 200 240 300 1150 1320
## Frequency 1 1 1 2 1 1 1 1 1 1
## Proportion 0.005 0.005 0.005 0.010 0.005 0.005 0.005 0.005 0.005 0.005
## ---------------------------------------------------------------------------
## CBR
## n missing distinct Info Mean Gmd .05 .10
## 209 0 42 0.998 23.17 12.93 10.0 10.0
## .25 .50 .75 .90 .95
## 13.0 21.0 31.0 41.0 45.6
##
## lowest : 8 9 10 11 12, highest: 45 46 47 48 50
## ---------------------------------------------------------------------------
## CDR
## n missing distinct Info Mean Gmd .05 .10
## 209 0 24 0.991 9.11 4.926 4.0 4.0
## .25 .50 .75 .90 .95
## 6.0 8.0 10.0 15.0 18.6
##
## lowest : 2 3 4 5 6, highest: 21 22 23 25 31
## ---------------------------------------------------------------------------
## Rate.of.natural.increase
## n missing distinct Info Mean Gmd .05 .10
## 209 0 41 0.999 1.407 1.193 -0.16 0.08
## .25 .50 .75 .90 .95
## 0.50 1.40 2.20 2.80 3.10
##
## lowest : -0.6 -0.5 -0.4 -0.3 -0.2, highest: 3.0 3.1 3.2 3.3 3.6
## ---------------------------------------------------------------------------
## Net.Migration.Rate
## n missing distinct Info Mean Gmd .05 .10
## 208 1 33 0.982 1 6.282 -7 -4
## .25 .50 .75 .90 .95
## -1 0 2 7 10
##
## lowest : -18 -17 -16 -11 -10, highest: 20 26 36 37 41
## ---------------------------------------------------------------------------
## ProjectedPopMid2025
## n missing distinct Info Mean Gmd .05 .10
## 209 0 142 1 38.27 62.39 0.10 0.20
## .25 .50 .75 .90 .95
## 1.10 7.70 26.20 66.64 119.84
##
## Value 0 20 40 60 80 100 120 180 200 220
## Frequency 122 39 17 11 4 3 5 1 1 2
## Proportion 0.584 0.187 0.081 0.053 0.019 0.014 0.024 0.005 0.005 0.010
##
## Value 300 360 1400 1480
## Frequency 1 1 1 1
## Proportion 0.005 0.005 0.005 0.005
## ---------------------------------------------------------------------------
## ProjectedPopMid2050
## n missing distinct Info Mean Gmd .05 .10
## 209 0 150 1 44.74 72.6 0.1 0.2
## .25 .50 .75 .90 .95
## 1.3 8.8 34.7 77.9 141.2
##
## Value 0 20 40 60 80 100 120 140 160 180
## Frequency 112 38 23 11 7 3 3 2 1 1
## Proportion 0.536 0.182 0.110 0.053 0.033 0.014 0.014 0.010 0.005 0.005
##
## Value 220 260 280 300 340 440 1440 1760
## Frequency 1 1 1 1 1 1 1 1
## Proportion 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005
## ---------------------------------------------------------------------------
## ProjectedPopChange_08_50Perc
## n missing distinct Info Mean Gmd .05 .10
## 209 0 126 1 47.84 61.61 -20.0 -13.0
## .25 .50 .75 .90 .95
## 6.0 38.0 75.0 124.4 153.4
##
## lowest : -35 -33 -29 -28 -27, highest: 205 216 220 261 263
## ---------------------------------------------------------------------------
## IMR
## n missing distinct Info Mean Gmd .05 .10
## 207 2 119 1 35.39 37.38 3.1 3.7
## .25 .50 .75 .90 .95
## 7.2 20.0 58.5 91.0 101.4
##
## lowest : 1.3 1.6 2.0 2.4 2.5, highest: 117.0 132.0 133.0 158.0 163.0
## ---------------------------------------------------------------------------
## WomandLifeTimeRiskMaternalDeath
## n missing distinct Info Mean Gmd .05 .10
## 171 38 118 1 3463 5352 14.0 22.0
## .25 .50 .75 .90 .95
## 46.5 290.0 4450.0 11000.0 16900.0
##
## lowest : 7 8 11 12 13, highest: 21500 25900 26600 29000 47600
## ---------------------------------------------------------------------------
## TFR
## n missing distinct Info Mean Gmd .05 .10
## 208 1 56 0.999 3.032 1.76 1.300 1.400
## .25 .50 .75 .90 .95
## 1.775 2.500 4.000 5.430 6.430
##
## lowest : 1.0 1.1 1.2 1.3 1.4, highest: 6.5 6.6 6.7 6.8 7.1
## ---------------------------------------------------------------------------
## PercPopLT15
## n missing distinct Info Mean Gmd .05 .10
## 209 0 37 0.999 29.93 12.25 14 15
## .25 .50 .75 .90 .95
## 20 30 39 44 46
##
## lowest : 13 14 15 16 17, highest: 45 46 47 48 49
## ---------------------------------------------------------------------------
## PercPopGT65
## n missing distinct Info Mean Gmd .05 .10
## 209 0 21 0.989 7.512 5.536 2 3
## .25 .50 .75 .90 .95
## 4 6 11 16 17
##
## lowest : 1 2 3 4 5, highest: 17 18 19 20 22
## ---------------------------------------------------------------------------
## e0Total
## n missing distinct Info Mean Gmd .05 .10
## 207 2 43 0.998 67.85 11.96 46.3 49.6
## .25 .50 .75 .90 .95
## 61.5 72.0 75.0 79.4 80.0
##
## lowest : 33 36 38 40 43, highest: 78 79 80 81 82
## ---------------------------------------------------------------------------
## e0Male
## n missing distinct Info Mean Gmd .05 .10
## 207 2 42 0.998 65.6 11.49 45.3 48.6
## .25 .50 .75 .90 .95
## 59.0 69.0 73.0 77.0 78.0
##
## lowest : 33 35 38 40 41, highest: 76 77 78 79 80
## ---------------------------------------------------------------------------
## e0Female
## n missing distinct Info Mean Gmd .05 .10
## 207 2 46 0.998 70.15 12.74 47.0 51.6
## .25 .50 .75 .90 .95
## 63.5 74.0 79.0 82.0 83.0
##
## lowest : 34 36 37 40 43, highest: 82 83 84 85 86
## ---------------------------------------------------------------------------
## PercUrban
## n missing distinct Info Mean Gmd .05 .10
## 208 1 79 1 55.94 28.04 17.00 23.40
## .25 .50 .75 .90 .95
## 35.75 57.50 74.50 88.60 95.95
##
## lowest : 10 12 13 15 16, highest: 93 94 97 98 100
## ---------------------------------------------------------------------------
## PercPopinUrbanGT750k
## n missing distinct Info Mean Gmd .05 .10
## 122 87 47 0.999 24.12 17.05 8 9
## .25 .50 .75 .90 .95
## 12 19 31 43 54
##
## lowest : 3 4 5 6 7, highest: 60 61 66 70 100
## ---------------------------------------------------------------------------
## PercPop1549HIVAIDS2001
## n missing distinct Info Mean Gmd .05 .10
## 128 81 45 0.977 2.434 3.722 0.100 0.100
## .25 .50 .75 .90 .95
## 0.100 0.500 1.725 6.120 14.145
##
## lowest : 0.1 0.2 0.3 0.4 0.5, highest: 16.9 23.9 26.0 26.3 26.5
## ---------------------------------------------------------------------------
## PercPop1549HIVAIDS2007
## n missing distinct Info Mean Gmd .05 .10
## 140 69 45 0.98 2.145 3.225 0.10 0.10
## .25 .50 .75 .90 .95
## 0.10 0.50 1.70 5.13 12.63
##
## lowest : 0.1 0.2 0.3 0.4 0.5, highest: 15.3 18.1 23.2 23.9 26.1
## ---------------------------------------------------------------------------
## PercMarWomContraALL
## n missing distinct Info Mean Gmd .05 .10
## 159 50 72 1 49.44 27 9.9 12.8
## .25 .50 .75 .90 .95
## 31.0 53.0 70.0 77.2 79.1
##
## lowest : 3 5 6 8 9, highest: 82 84 85 86 90
## ---------------------------------------------------------------------------
## PercMarWomContraModern
## n missing distinct Info Mean Gmd .05 .10
## 168 41 69 1 38.61 26.37 6.00 8.70
## .25 .50 .75 .90 .95
## 17.75 39.00 58.00 70.00 74.30
##
## lowest : 1 2 4 5 6, highest: 75 76 78 79 90
## ---------------------------------------------------------------------------
## PercPpUnderNourished0204
## n missing distinct Info Mean Gmd .05 .10
## 173 36 43 0.986 14.83 15.59 2.5 2.5
## .25 .50 .75 .90 .95
## 3.0 8.0 23.0 35.0 46.0
##
## lowest : 2.5 3.0 4.0 5.0 6.0, highest: 56.0 60.0 66.0 74.0 75.0
## ---------------------------------------------------------------------------
## MotorVehper1000Pop0005
## n missing distinct Info Mean Gmd .05 .10
## 131 78 113 1 249.8 254.4 4.0 13.0
## .25 .50 .75 .90 .95
## 54.5 159.0 454.5 580.0 685.5
##
## lowest : 1 2 3 5 6, highest: 731 750 756 765 787
## ---------------------------------------------------------------------------
## PercPopwAccessImprovedWaterSource
## n missing distinct Info Mean Gmd .05 .10
## 178 31 48 0.99 84.04 18.74 47 58
## .25 .50 .75 .90 .95
## 73 91 99 100 100
##
## lowest : 22 29 40 42 43, highest: 96 97 98 99 100
## ---------------------------------------------------------------------------
## GNIPPPperCapitaUSDollars
## n missing distinct Info Mean Gmd .05 .10
## 176 33 167 1 11878 13564 747.5 1085.0
## .25 .50 .75 .90 .95
## 2110.0 5950.0 15185.0 34485.0 38442.5
##
## lowest : 290 330 400 470 630, highest: 48520 49900 49970 53690 64400
## ---------------------------------------------------------------------------
## PopDensPerSqKM
## n missing distinct Info Mean Gmd .05 .10
## 209 0 147 1 472.8 814.7 4.0 11.0
## .25 .50 .75 .90 .95
## 31.0 77.0 195.0 371.0 645.6
##
## Value 0 500 1000 1500 6500 7000 21000 34000
## Frequency 167 33 4 1 1 1 1 1
## Proportion 0.799 0.158 0.019 0.005 0.005 0.005 0.005 0.005
## ---------------------------------------------------------------------------
## PopDensPerSqMile
## n missing distinct Info Mean Gmd .05 .10
## 209 0 147 1 1225 2110 10.36 28.49
## .25 .50 .75 .90 .95
## 80.29 199.43 505.05 960.89 1672.10
##
## Value 0 1000 2000 3000 16000 18000 55000 88000
## Frequency 156 40 5 4 1 1 1 1
## Proportion 0.746 0.191 0.024 0.019 0.005 0.005 0.005 0.005
## ---------------------------------------------------------------------------
Identifying how many countries are missing e0Total variable
summary(prb$e0Total)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 33.00 61.50 72.00 67.85 75.00 82.00 2
The two countries missing e0Total data are Andorra and Monaco.