Creating Vectors x,y,z using “c” or “concatenate command”
x <- c(5,10,15,20,25,30)
y <- c(-1,NA,75,3,5,8)
z <- c(5)
Printing Vectors x,y,z
print(x)
## [1] 5 10 15 20 25 30
print(y)
## [1] -1 NA 75 3 5 8
print(z)
## [1] 5
Multiplying Vectors, creating new x1,y1
x1 <- x*z
y1 <- y*z
Printing Vectors x1,y1
print(x1)
## [1] 25 50 75 100 125 150
print(y1)
## [1] -5 NA 375 15 25 40
Replacing missing value in y and print new y
y <- ifelse(test = is.na(y)==T, yes=2.5,no=y)
print(y)
## [1] -1.0 2.5 75.0 3.0 5.0 8.0
Load the PRB data as table and view
library(readr)
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.
names(prb) #print the column names
## [1] "Y"
## [2] "X"
## [3] "ID"
## [4] "Country"
## [5] "Continent"
## [6] "Region"
## [7] "Year"
## [8] "Population."
## [9] "CBR"
## [10] "CDR"
## [11] "Rate.of.natural.increase"
## [12] "Net.Migration.Rate"
## [13] "ProjectedPopMid2025"
## [14] "ProjectedPopMid2050"
## [15] "ProjectedPopChange_08_50Perc"
## [16] "IMR"
## [17] "WomandLifeTimeRiskMaternalDeath"
## [18] "TFR"
## [19] "PercPopLT15"
## [20] "PercPopGT65"
## [21] "e0Total"
## [22] "e0Male"
## [23] "e0Female"
## [24] "PercUrban"
## [25] "PercPopinUrbanGT750k"
## [26] "PercPop1549HIVAIDS2001"
## [27] "PercPop1549HIVAIDS2007"
## [28] "PercMarWomContraALL"
## [29] "PercMarWomContraModern"
## [30] "PercPpUnderNourished0204"
## [31] "MotorVehper1000Pop0005"
## [32] "PercPopwAccessImprovedWaterSource"
## [33] "GNIPPPperCapitaUSDollars"
## [34] "PopDensPerSqKM"
## [35] "PopDensPerSqMile"
View(prb) #open it in a viewer
Print the first 10 countries
head(prb$Country, 10)
## [1] "Afghanistan" "Albania" "Algeria"
## [4] "Andorra" "Angola" "Antigua and Barbuda"
## [7] "Argentina" "Armenia" "Australia"
## [10] "Austria"
Two ways to show how many countries are in the list
1 using Summary
print(summary(prb$Country))
## Length Class Mode
## 209 character character
2 using Length
print(length(prb$Country))
## [1] 209
3 Missing e0Total
print(table(is.na(prb$e0Total)))
##
## FALSE TRUE
## 207 2
print(sum(is.na(prb$e0Total)))
## [1] 2
Print the countries:
coutrywitot<-subset(prb, ifelse(test = is.na(prb$e0Total)==T, TRUE,FALSE))
print(coutrywitot$Country)
## [1] "Andorra" "Monaco"