The task is to convert an html file,json and xml file into a dataframe into R at first I wasnt sure how to read the files from the web so I did read it locally.But I later tailored each file for reproducibility, so I put the files into Github and I used the readlines function to read the raw data and then I parsed each file to its specific function i.e html file to htmlparse, xml file to xml parse and json file to Fromjson. From there I did my best to convert the information into a R data_frame. After reading each of the information from the pages I would say that the data frames do look smiliar.
## converting html page to a R data frame
## wasn't sure how to read the direct html file since I used sublime text edit to make the html so I used readLines to read from the raw data from Github
library(XML)
library(jsonlite)
## Warning: package 'jsonlite' was built under R version 4.1.3
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
url <- readLines("https://raw.githubusercontent.com/AldataSci/Data607Week7Assignment/main/table.html")
parsed_detail <- htmlParse(url)
tables <- readHTMLTable(url)
table <- as.data.frame(tables)
table
## NULL.Title NULL.Author NULL.Attributes
## 1 Deep Work Cal Newport Learning how to work with deep focus
## 2 Harry Potter J.K Rowling Adventures of Harry Potter in the Wizarding World
## 3 Attached Amir Levante Psychology and Attachment Theory
## getting an xml file using xmlToDataFrame to convert an xml file into a Data Frame
URL <- readLines("https://raw.githubusercontent.com/AldataSci/Data607Week7Assignment/main/book.xml")
book_xml <- xmlParse("C://Users//Al Haque//Desktop//AL Info Folder//book.xml")
book <-xmlToDataFrame(book_xml)
book
## Title Author
## 1 Deep Work Cal Newport
## 2 Harry Potter J.K Rowling
## 3 Attached Amir Levante
## Attributes
## 1 Learning How to Work with Deep Focus
## 2 Adventures of Harry Potter in the Wizarding World
## 3 Studies of Attachment theory in Psychology
##json file.
## converting a json file into a Data Frame
link <- "https://raw.githubusercontent.com/AldataSci/Data607Week7Assignment/main/book.json"
book_json <- fromJSON(link) %>%
as.data.frame()
book_json
## books.Title books.Author books.Attributes
## 1 Deep Work Cal Newport Learning How to Work with Deep Focus
## 2 Harry Potter J.K Rowling Adventures of Harry Potter in the Wizarding World
## 3 Attached Amir Levante Studies of Attachment Theory in Psychology