Assignment:-
Pick three of your favorite books on one of your favorite subjects. At least one of the books should have more than one author. For each book, include the title, authors, and two or three other attributes that you find interesting. Take the information that you’ve selected about these three books, and separately create three files which store the book’s information in HTML (using an html table), XML, and JSON formats (e.g. “books.html”, “books.xml”, and “books.json”). To help you better understand the different file structures, I’d prefer that you create each of these files “by hand” unless you’re already very comfortable with the file formats. Write R code, using your packages of choice, to load the information from each of the three sources into separate R data frames. Are the three data frames identical?:
Reading Data of the favourite books from json file
I created the files and saved them locally which can now be found in Github.
library(jsonlite)
library(knitr)
favbooks_json <- fromJSON("fav-books.json", flatten=TRUE)
JSONdf <- data.frame(favbooks_json)
kable(JSONdf)
Title | Author | Category | Publisher | Isbn | URL |
---|---|---|---|---|---|
Make Your Bed: Little Things That Can Change Your Life…And Maybe the World. | William H. McRaven | Inspiration | Grand Central Publishing (April 4, 2017) | 1455570249 | https://www.amazon.com/Make-Your-Bed-Little-Things/dp/1455570249/ref=sr_1_1?ie=UTF8&qid=1521411090&sr=8-1&keywords=books+best+sellers |
Children of Time | Adrian Tchaikovsky | Space Science | Pan Macmillan; Reprint edition (July 1, 2016) | 1447273303 | https://www.amazon.com/Children-Time-Adrian-Tchaikovsky/dp/1447273303/ref=sr_1_14?ie=UTF8&qid=1521411800&sr=8-14&keywords=space+science+book |
The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness | Dave Ramsey | Money Management, Financial | Thomas Nelson; 1 edition (September 17, 2013) | 1595555277 | https://www.amazon.com/Total-Money-Makeover-Classic-Financial/dp/1595555277/ref=sr_1_3?ie=UTF8&qid=1521412017&sr=8-3&keywords=money+management+books |
Reading Data of the favourite books from XML file
library("XML")
library("methods")
favbooks_xml <- xmlParse("fav-books.xml")
XMLdf <- xmlToDataFrame(favbooks_xml)
kable(XMLdf)
Title | Author | Category | Publisher | ISBN-10 | URL |
---|---|---|---|---|---|
Make Your Bed: Little Things That Can Change Your Life…And Maybe the World. | William H. McRaven | Inspiration | Grand Central Publishing (April 4, 2017) | 1455570249 | “https://www.amazon.com/Make-Your-Bed-Little-Things/dp/1455570249/ref=sr_1_1?ie=UTF8%26qid=1521411090%26sr=8-1%26keywords=books+best+sellers” |
Children of Time | Adrian Tchaikovsky | Space Science | Pan Macmillan; Reprint edition (July 1, 2016) | 1447273303 | ‘https://www.amazon.com/Children-Time-Adrian-Tchaikovsky/dp/1447273303/ref=sr_1_14?ie=UTF8%26qid=1521411800%26sr=8-14%26keywords=space+science+book’ |
The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness | Dave Ramsey | Money Management, Financial | Thomas Nelson; 1 edition (September 17, 2013) | 1595555277 | ‘https://www.amazon.com/Total-Money-Makeover-Classic-Financial/dp/1595555277/ref=sr_1_3?ie=UTF8%26qid=1521412017%26sr=8-3%26keywords=money+management+books’ |
Reading Data of the favourite books from HTML file
favbooks_html <- htmlParse("fav-books.html")
HTMLdf <- data.frame(readHTMLTable(favbooks_html))
kable(HTMLdf)
NULL.Title | NULL.Author | NULL.Category | NULL.Publisher | NULL.ISBN.10 | NULL.URL |
---|---|---|---|---|---|
Make Your Bed: Little Things That Can Change Your Life…And Maybe the World. | William H. McRaven | Inspiration | Grand Central Publishing (April 4, 2017) | 1455570249 | https://www.amazon.com/Make-Your-Bed-Little-Things/dp/1455570249/ref=sr_1_1?ie=UTF8&qid=1521411090&sr=8-1&keywords=books+best+sellers |
Children of Time | Adrian Tchaikovsky | Space Science | Pan Macmillan; Reprint edition (July 1, 2016) | 1447273303 | https://www.amazon.com/Children-Time-Adrian-Tchaikovsky/dp/1447273303/ref=sr_1_14?ie=UTF8&qid=1521411800&sr=8-14&keywords=space+science+book |
The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness | Dave Ramsey | Money Management, Financial | Thomas Nelson; 1 edition (September 17, 2013) | 1595555277 | https://www.amazon.com/Total-Money-Makeover-Classic-Financial/dp/1595555277/ref=sr_1_3?ie=UTF8&qid=1521412017&sr=8-3&keywords=money+management+books |
I wanted to mask all the URLs into hyperlinks so its neater but couldnt do it due to lack of time.
Analysis:- The data is the same in all the dataframes.
R provides different methods and functionalities to import data from different format.
When data is same in all the sources the R language is able to parse data in different formats and extract the relevent information