R code, using your packages of choice, to load the information from each of the three sources into separate R data frames.
R code.
package your assignment solution up into an .Rmd file and publish to \(rpubs.com\). * [This will also require finding a way to make your three text files accessible from the web].Files book.html, book.xml & book.json are located in Week 7 Folder of my GitHub Repository
All url’s were stored to there respective character variable:
Importing involve the following
read_html() from the rvest library, and is imported as class XMLInternalDocumentxmlParse() from the XML library and is imported as class xml_documentfromJSON() from the jsonlite library imported as a listhtml_table() function, the resulting tibble is then converted to a traditional data.frame with the function as.data.frame(). NOTE1\(^,\) 2xmlToDataFrame function from XML package.NOTE3do.call base function is used to utilize a function call in this operation rbind() on list. lapply() is used for performing functions on a list, in this case formatting the list into rows and columns. The combined methods create the desired data.framedf_html<-
as.data.frame(html_table(import_html)) %>%
row_to_names(1) %>%
tibble::remove_rownames()
df_xml<-xmlToDataFrame(import_xml)
colnames(df_xml)<- str_to_title(colnames(df_xml))
df_json <- do.call("rbind", lapply(import_json, data.frame))
rownames(df_json)<-NULL| Book Title | Author(s) | Year Published | Publisher | Price ($) |
|---|---|---|---|---|
| Bayesian Theory 1st Edition | Jose M. Bernardo, Adrian F. M. Smith | 2000 | Wiley Series in Probability and Statistics | 98.03 |
| The Bayesian Choice: From Decision-Theoretic Foundations to Computational Implementation 2nd Edition | Christian P. Robert | 2007 | Springer Verlag | 43.99 |
| A First Course in Bayesian Statistical Methods 1st Edition | Peter D. Hoff | 2010 | Springer Verlag | 46.60 |
| Title | Author | Year_published | Publisher | Price |
|---|---|---|---|---|
| Bayesian Theory 1st Edition | Jose M. Bernardo, Adrian F. M. Smith | 2000 | Wiley Series in Probability and Statistics | 98.03 |
| The Bayesian Choice: From Decision-Theoretic Foundations to Computational Implementation 2nd Edition | Christian P. Robert | 2007 | Springer Verlag | 43.99 |
| A First Course in Bayesian Statistical Methods 1st Edition | Peter D. Hoff | 2010 | Springer Verlag | 46.60 |
| BookName | Author | YearPublished | Publisher | Price |
|---|---|---|---|---|
| Bayesian Theory 1st Edition | Jose M. Bernardo, Adrian F. M. Smith | 2000 | Wiley Series in Probability and Statistics | 98.03 |
| The Bayesian Choice: From Decision-Theoretic Foundations to Computational Implementation 2nd Edition | Christian P. Robert | 2007 | Springer Verlag | 43.99 |
| A First Course in Bayesian Statistical Methods 1st Edition | Peter D. Hoff | 2010 | Springer Verlag | 46.60 |
Are the three data frames identical?
No, they are not. The column names are imported according the the naming conventions of where they were imported (although can be excluded or altered on import). Each requires their own library to import and the class types of each on import is distinct. As such, the approach to changing the data into a data.frame are also different.