Introduction

In this assignment I will be creating 3 different data structures of some of my favorite books, Money ball, Red Notice, and Freakonomics.

First off I am using jsonlite to grab and read the json data from github.

url_json <- 'https://raw.githubusercontent.com/btc2628/DATA607/main/Week%207%20Assignment/books.json'
jsonData <- jsonlite::fromJSON(url_json)
df_json <- as.data.frame(jsonData)
kable(df_json)
ISBN Title Author Rating
9.780393e+12 Moneyball: The Art of Winning an Unfair Game Micheal Lewis 4.26
9.781477e+12 Red Notice: A True Story of High Finance, Murder, and One Man’s Fight for Justice Bill Browder 4.44
9.780061e+12 Freakonomics Steven D. Levitt 4.01
9.780061e+12 Freakonomics Stephen J. Dubner 4.01

For XML I am first using httr to grab the data then XML to parse and transform it to a dataframe.

xml_raw <- GET("https://raw.githubusercontent.com/btc2628/DATA607/main/Week%207%20Assignment/books.xml")
XMLData <- XML::xmlParse(xml_raw)
df_XML <- XML::xmlToDataFrame(XMLData)
kable(df_XML)
ISBN Title Author Rating
9780393057652 Moneyball: The Art of Winning an Unfair Game Micheal Lewis 4.26
9781476755748 Red Notice: A True Story of High Finance, Murder, and One Man’s Fight for Justice Bill Browder 4.44
9780060731335 Freakonomics Steven D. Levitt 4.01
9780060731335 Freakonomics Stephen J. Dubner 4.01

Lastly I am using rvest to read in the html data and transform it into a dataframe.

url_html<- 'https://raw.githubusercontent.com/btc2628/DATA607/main/Week%207%20Assignment/books.html'
htmlData <- rvest::read_html(url_html)
df_html <- rvest::html_table(htmlData, fill = TRUE)[[1]]
kable(df_html)
ISBN Title Author Rating
9.780393e+12 Moneyball: The Art of Winning an Unfair Game Micheal Lewis 4.26
9.781477e+12 Red Notice: A True Story of High Finance, Murder, and One Man’s Fight for Justice Bill Browder 4.44
9.780061e+12 Freakonomics Steven D. Levitt 4.01
9.780061e+12 Freakonomics Stephen J. Dubner 4.01

Conlusion

This project has illustrated the different ways in which data can be formatted and strategies to transform that data to be consistent with dataframe structure for easy use.