install.packages("curl")
library("curl")
install.packages("httr")
library("httr")
install.packages("rvest")
library("rvest")
covid19_url <- "https://en.wikipedia.org/w/index.php?title=Template:COVID-19_testing_by_country" response <- GET(covid19_url) response
covid19_root_node <- read_html( "https://en.wikipedia.org/w/index.php?title=Template:COVID-19_testing_by_country") covid19_root_node
covid19_table_node <- html_node(covid19_root_node, "table") covid19_table_node
covid19_data_frame <- html_table(covid19_table_node) head(covid19_data_frame)
summary(covid19_data_frame)
wiki_covid19_data_frame <- preprocess_covid_data_frame(covid19_data_frame) wiki_covid19_data_frame
summary(wiki_covid19_data_frame)
write.csv(wiki_covid19_data_frame, file = "covid.csv", row.names = FALSE)
wd <- getwd()
file_path <- paste(wd, sep="", "/covid.csv")
print(file_path) file.exists(file_path)
#covid_csv_file <- download.file("https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-RP0101EN-Coursera/v2/dataset/covid.csv", destfile="covid.csv") #covid_data_frame_csv <- read.csv("covid.csv", header=TRUE, sep=",")
covid_data_frame_csv <- read.csv("covid.csv", header=TRUE, sep=",")
covid_data_frame_csv[ 5:10, c( "country", "confirmed") ]
confirmed_cases <- covid_data_frame_csv[ , 4] confirmed_cases total_confirmed_cases <- sum(confirmed_cases) total_confirmed_cases
tested_cases <- covid_data_frame_csv[ , 3] tested_cases total_tested_cases <- sum(tested_cases) total_tested_cases
positive_ratio <- total_confirmed_cases/total_tested_cases positive_ratio
country_column <- covid_data_frame_csv[ , 1] country_column
class(country_column)
as.character ( country_column)
sort(country_column)
Country_ZtoA <- sort(country_column, decreasing = TRUE) Country_ZtoA
print( Country_ZtoA)
matches <- regexpr("United.+", covid_data_frame_csv[ ,"country"]) countires_start_with_United<- regmatches(covid_data_frame_csv[ ,"country"], matches) countires_start_with_United
print(countires_start_with_United)
wiki_covid19_data_frame[1, c( "country", "confirmed", "confirmed.population.ratio") ]
wiki_covid19_data_frame[ 20, c("country", "confirmed", "confirmed.population.ratio") ]
if (49621 > 1491) { print( "Afghanistan has larger ratio of confirmed cases to population") } else { print( "Bhutan has larger ratio of confirmed cases to population") }
threshold = "lessRisk"
if (threshold == "lessRisk"){
subset(wiki_covid19_data_frame, confirmed.population.ratio < .01)
} else {
subset(wiki_covid19_data_frame, confirmed.population.ratio > .01)
}