Purpose

The purpose of this assignment is to access the NY Times API, pull JSON data, and transform it into a data frame. Below I load the required packages.

library(tidyverse)
library(httr2)
library(data.table)

NY Times API

I decided to pull the current NY Times best seller list for hard cover non-fiction books. The URL to pull this information follows the below format:

https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=yourkey

I created an object request_url to hold the url. However I have hidden the code to conceal my api key.

Pulling the api data

Below I pull the data from the NY Times API

apiResponse <- request(request_url) |> req_perform()

summary(apiResponse)
##             Length Class         Mode       
## method          1  -none-        character  
## url             1  -none-        character  
## status_code     1  -none-        numeric    
## headers        21  httr2_headers list       
## body        25192  -none-        raw        
## request         7  httr2_request list       
## cache           0  -none-        environment

The result is a list of 7 with various attributes

Extracting data

Below I parse the JSON content.

bookList <- apiResponse |> resp_body_json()

summary(bookList)
##               Length Class  Mode     
## status         1     -none- character
## copyright      1     -none- character
## num_results    1     -none- numeric  
## last_modified  1     -none- character
## results       12     -none- list

It seems like the results list might have the information we are looking for

summary(bookList$results)
##                            Length Class  Mode     
## list_name                   1     -none- character
## list_name_encoded           1     -none- character
## bestsellers_date            1     -none- character
## published_date              1     -none- character
## published_date_description  1     -none- character
## next_published_date         1     -none- character
## previous_published_date     1     -none- character
## display_name                1     -none- character
## normal_list_ends_at         1     -none- numeric  
## updated                     1     -none- character
## books                      15     -none- list     
## corrections                 0     -none- list

Specifically, bookList is a list that has nested list. Based on the above, the books list might have the info on the best sellers. I investigate below

bookInfo <- bookList$results$books

summary(bookInfo)
##       Length Class  Mode
##  [1,] 26     -none- list
##  [2,] 26     -none- list
##  [3,] 26     -none- list
##  [4,] 26     -none- list
##  [5,] 26     -none- list
##  [6,] 26     -none- list
##  [7,] 26     -none- list
##  [8,] 26     -none- list
##  [9,] 26     -none- list
## [10,] 26     -none- list
## [11,] 26     -none- list
## [12,] 26     -none- list
## [13,] 26     -none- list
## [14,] 26     -none- list
## [15,] 26     -none- list
glimpse(bookInfo)
## List of 15
##  $ :List of 26
##   ..$ rank                : int 1
##   ..$ rank_last_week      : int 2
##   ..$ weeks_on_list       : int 3
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 1
##   ..$ primary_isbn10      : chr "0063061198"
##   ..$ primary_isbn13      : chr "9780063061194"
##   ..$ publisher           : chr "Harper"
##   ..$ description         : chr "The author of “Red-Handed” depicts a scheme involving the Chinese Communist Party’s covert operations in America."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "BLOOD MONEY"
##   ..$ author              : chr "Peter Schweizer"
##   ..$ contributor         : chr "by Peter Schweizer"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780063061194.jpg"
##   ..$ book_image_width    : int 331
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0063061198?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/2641ab34-1d1b-570d-81dc-ca874279ea5a"
##  $ :List of 26
##   ..$ rank                : int 2
##   ..$ rank_last_week      : int 4
##   ..$ weeks_on_list       : int 51
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0593236599"
##   ..$ primary_isbn13      : chr "9780593236598"
##   ..$ publisher           : chr "Harmony"
##   ..$ description         : chr "A look at recent scientific research on aging and longevity."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "OUTLIVE"
##   ..$ author              : chr "Peter Attia with Bill Gifford"
##   ..$ contributor         : chr "by Peter Attia with Bill Gifford"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780593236598.jpg"
##   ..$ book_image_width    : int 385
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0593236599?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 3
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/69f6e624-4f30-59d6-8103-816d17ae5ec1"
##  $ :List of 26
##   ..$ rank                : int 3
##   ..$ rank_last_week      : int 1
##   ..$ weeks_on_list       : int 2
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0063263904"
##   ..$ primary_isbn13      : chr "9780063263901"
##   ..$ publisher           : chr "Dey Street"
##   ..$ description         : chr "The multiple Emmy Award-winning producer of “RuPaul’s Drag Race” traces his journey from his childhood in San D"| __truncated__
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "THE HOUSE OF HIDDEN MEANINGS"
##   ..$ author              : chr "RuPaul"
##   ..$ contributor         : chr "by RuPaul"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780063263901.jpg"
##   ..$ book_image_width    : int 331
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0063263904?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/4dadcf0e-22e8-5bf6-8656-103432db13df"
##  $ :List of 26
##   ..$ rank                : int 4
##   ..$ rank_last_week      : int 3
##   ..$ weeks_on_list       : int 47
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0385534264"
##   ..$ primary_isbn13      : chr "9780385534260"
##   ..$ publisher           : chr "Doubleday"
##   ..$ description         : chr "The survivors of a shipwrecked British vessel on a secret mission during an imperial war with Spain have differ"| __truncated__
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "THE WAGER"
##   ..$ author              : chr "David Grann"
##   ..$ contributor         : chr "by David Grann"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780385534260.jpg"
##   ..$ book_image_width    : int 329
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0385534264?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 4
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/92ec85ca-4cff-59b6-94a3-b81002bfc8e6"
##  $ :List of 26
##   ..$ rank                : int 5
##   ..$ rank_last_week      : int 0
##   ..$ weeks_on_list       : int 1
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0374299404"
##   ..$ primary_isbn13      : chr "9780374299408"
##   ..$ publisher           : chr "Farrar, Straus & Giroux"
##   ..$ description         : chr "The Pulitzer Prize-winning author of “Gilead” illuminates the literary aspects of the Bible’s first book."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "READING GENESIS"
##   ..$ author              : chr "Marilynne Robinson"
##   ..$ contributor         : chr "by Marilynne Robinson"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780374299408.jpg"
##   ..$ book_image_width    : int 333
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0374299404?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/039dff37-b184-5ac4-ba90-a3297c34f952"
##  $ :List of 26
##   ..$ rank                : int 6
##   ..$ rank_last_week      : int 5
##   ..$ weeks_on_list       : int 15
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0316572063"
##   ..$ primary_isbn13      : chr "9780316572064"
##   ..$ publisher           : chr "Little, Brown"
##   ..$ description         : chr "The former congresswoman from Wyoming recounts how she helped lead the Select Committee to Investigate the Jan."| __truncated__
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "OATH AND HONOR"
##   ..$ author              : chr "Liz Cheney"
##   ..$ contributor         : chr "by Liz Cheney"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780316572064.jpg"
##   ..$ book_image_width    : int 323
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0316572063?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 5
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/dc0a4f2d-d896-5f85-93c2-5fb756999bc3"
##  $ :List of 26
##   ..$ rank                : int 7
##   ..$ rank_last_week      : int 6
##   ..$ weeks_on_list       : int 3
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "1982163895"
##   ..$ primary_isbn13      : chr "9781982163891"
##   ..$ publisher           : chr "Simon & Schuster"
##   ..$ description         : chr "The tech journalist and podcast host gives an overview of the tech industry and the foibles of its founders."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "BURN BOOK"
##   ..$ author              : chr "Kara Swisher"
##   ..$ contributor         : chr "by Kara Swisher"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9781982163891.jpg"
##   ..$ book_image_width    : int 331
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/1982163895?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/e671fbbc-e5e3-56c2-8c98-b244c24c6527"
##  $ :List of 26
##   ..$ rank                : int 8
##   ..$ rank_last_week      : int 0
##   ..$ weeks_on_list       : int 1
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0593474139"
##   ..$ primary_isbn13      : chr "9780593474136"
##   ..$ publisher           : chr "Dutton"
##   ..$ description         : chr "The CNN anchor and chief national security analyst examines shifts in the global order, including how they impa"| __truncated__
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "THE RETURN OF GREAT POWERS"
##   ..$ author              : chr "Jim Sciutto"
##   ..$ contributor         : chr "by Jim Sciutto"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780593474136.jpg"
##   ..$ book_image_width    : int 333
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0593474139?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/fc098450-7529-5e46-ac97-98dd44cba00c"
##  $ :List of 26
##   ..$ rank                : int 9
##   ..$ rank_last_week      : int 7
##   ..$ weeks_on_list       : int 2
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 1
##   ..$ primary_isbn10      : chr "0593542924"
##   ..$ primary_isbn13      : chr "9780593542927"
##   ..$ publisher           : chr "Sentinel"
##   ..$ description         : chr "Shrier makes her case that the mental health industry has a negative impact on American children."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "BAD THERAPY"
##   ..$ author              : chr "Abigail Shrier"
##   ..$ contributor         : chr "by Abigail Shrier"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780593542927.jpg"
##   ..$ book_image_width    : int 331
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0593542924?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/57514760-1473-5d01-b541-5264404461e1"
##  $ :List of 26
##   ..$ rank                : int 10
##   ..$ rank_last_week      : int 8
##   ..$ weeks_on_list       : int 3
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "164421363X"
##   ..$ primary_isbn13      : chr "9781644213636"
##   ..$ publisher           : chr "Seven Stories"
##   ..$ description         : chr "A legal analyst for NBC News and MSNBC looks at the effects of disinformation on law and politics."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "ATTACK FROM WITHIN"
##   ..$ author              : chr "Barbara McQuade"
##   ..$ contributor         : chr "by Barbara McQuade"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9781644213636.jpg"
##   ..$ book_image_width    : int 339
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/164421363X?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/3d172712-aa3a-5126-a2cd-0790eea5b79f"
##  $ :List of 26
##   ..$ rank                : int 11
##   ..$ rank_last_week      : int 0
##   ..$ weeks_on_list       : int 34
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "1250866448"
##   ..$ primary_isbn13      : chr "9781250866448"
##   ..$ publisher           : chr "Flatiron"
##   ..$ description         : chr "The late actor, known for playing Chandler Bing on “Friends,” shares stories from his childhood and his struggl"| __truncated__
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "FRIENDS, LOVERS, AND THE BIG TERRIBLE THING"
##   ..$ author              : chr "Matthew Perry"
##   ..$ contributor         : chr "by Matthew Perry"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9781250866448.jpg"
##   ..$ book_image_width    : int 329
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/1250866448?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 4
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/04988f91-5b03-5eb4-ae17-89fda0e7051a"
##  $ :List of 26
##   ..$ rank                : int 12
##   ..$ rank_last_week      : int 12
##   ..$ weeks_on_list       : int 75
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "1982185821"
##   ..$ primary_isbn13      : chr "9781982185824"
##   ..$ publisher           : chr "Simon & Schuster"
##   ..$ description         : chr "The actress and filmmaker describes her eating disorders and difficult relationship with her mother."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "I'M GLAD MY MOM DIED"
##   ..$ author              : chr "Jennette McCurdy"
##   ..$ contributor         : chr "by Jennette McCurdy"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9781982185824.jpg"
##   ..$ book_image_width    : int 329
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/1982185821?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 3
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/be73b1c3-c238-5232-af55-bf70c59cb907"
##  $ :List of 26
##   ..$ rank                : int 13
##   ..$ rank_last_week      : int 0
##   ..$ weeks_on_list       : int 17
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "059349993X"
##   ..$ primary_isbn13      : chr "9780593499931"
##   ..$ publisher           : chr "Ballantine"
##   ..$ description         : chr "A hospice nurse shares some of her most impactful experiences and questions some of society's beliefs around end-of-life care."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "THE IN-BETWEEN"
##   ..$ author              : chr "Hadley Vlahos"
##   ..$ contributor         : chr "by Hadley Vlahos"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780593499931.jpg"
##   ..$ book_image_width    : int 331
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/059349993X?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 3
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/9699c550-34ce-56c6-a242-3359bdeca897"
##  $ :List of 26
##   ..$ rank                : int 14
##   ..$ rank_last_week      : int 0
##   ..$ weeks_on_list       : int 1
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0374298343"
##   ..$ primary_isbn13      : chr "9780374298340"
##   ..$ publisher           : chr "Farrar, Straus & Giroux"
##   ..$ description         : chr "A Harvard University law professor looks at how the founding of Israel has transformed Judaism."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "TO BE A JEW TODAY"
##   ..$ author              : chr "Noah Feldman"
##   ..$ contributor         : chr "by Noah Feldman"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780374298340.jpg"
##   ..$ book_image_width    : int 333
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0374298343?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 1
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/c7e7e4da-ad26-5740-a47c-8ba173ae5fe9"
##  $ :List of 26
##   ..$ rank                : int 15
##   ..$ rank_last_week      : int 0
##   ..$ weeks_on_list       : int 1
##   ..$ asterisk            : int 0
##   ..$ dagger              : int 0
##   ..$ primary_isbn10      : chr "0063318628"
##   ..$ primary_isbn13      : chr "9780063318625"
##   ..$ publisher           : chr "Mariner"
##   ..$ description         : chr "Two journalists for The Wall Street Journal detail the rise of Formula 1 racing."
##   ..$ price               : chr "0.00"
##   ..$ title               : chr "THE FORMULA"
##   ..$ author              : chr "Joshua Robinson and Jonathan Clegg"
##   ..$ contributor         : chr "by Joshua Robinson and Jonathan Clegg"
##   ..$ contributor_note    : chr ""
##   ..$ book_image          : chr "https://storage.googleapis.com/du-prd/books/images/9780063318625.jpg"
##   ..$ book_image_width    : int 331
##   ..$ book_image_height   : int 500
##   ..$ amazon_product_url  : chr "https://www.amazon.com/dp/0063318628?tag=NYTBSREV-20"
##   ..$ age_group           : chr ""
##   ..$ book_review_link    : chr ""
##   ..$ first_chapter_link  : chr ""
##   ..$ sunday_review_link  : chr ""
##   ..$ article_chapter_link: chr ""
##   ..$ isbns               :List of 1
##   .. ..$ :List of 2
##   ..$ buy_links           :List of 6
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   .. ..$ :List of 2
##   ..$ book_uri            : chr "nyt://book/4981d8fb-009c-5bde-b2b9-ed43cd786b79"

bookInfo is a list of 15, the top 15 best sellers in the non-fiction hardcover category. For each book in the top 15, there is a list of 26 different variables.

Below, I bind the list of 15, with 26 variable for each of the 15, into a data frame by binding by rows.

bookInfoDF <- as.data.frame(do.call(rbind,bookInfo))

glimpse(bookInfoDF)
## Rows: 15
## Columns: 26
## $ rank                 <list> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
## $ rank_last_week       <list> 2, 4, 1, 3, 0, 5, 6, 0, 7, 8, 0, 12, 0, 0, 0
## $ weeks_on_list        <list> 3, 51, 2, 47, 1, 15, 3, 1, 2, 3, 34, 75, 17, 1, 1
## $ asterisk             <list> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
## $ dagger               <list> 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0
## $ primary_isbn10       <list> "0063061198", "0593236599", "0063263904", "03855…
## $ primary_isbn13       <list> "9780063061194", "9780593236598", "9780063263901…
## $ publisher            <list> "Harper", "Harmony", "Dey Street", "Doubleday", …
## $ description          <list> "The author of “Red-Handed” depicts a scheme inv…
## $ price                <list> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", …
## $ title                <list> "BLOOD MONEY", "OUTLIVE", "THE HOUSE OF HIDDEN M…
## $ author               <list> "Peter Schweizer", "Peter Attia with Bill Giffor…
## $ contributor          <list> "by Peter Schweizer", "by Peter Attia with Bill …
## $ contributor_note     <list> "", "", "", "", "", "", "", "", "", "", "", "", …
## $ book_image           <list> "https://storage.googleapis.com/du-prd/books/ima…
## $ book_image_width     <list> 331, 385, 331, 329, 333, 323, 331, 333, 331, 339…
## $ book_image_height    <list> 500, 500, 500, 500, 500, 500, 500, 500, 500, 500…
## $ amazon_product_url   <list> "https://www.amazon.com/dp/0063061198?tag=NYTBSR…
## $ age_group            <list> "", "", "", "", "", "", "", "", "", "", "", "", …
## $ book_review_link     <list> "", "", "", "", "", "", "", "", "", "", "", "", …
## $ first_chapter_link   <list> "", "", "", "", "", "", "", "", "", "", "", "", …
## $ sunday_review_link   <list> "", "", "", "", "", "", "", "", "", "", "", "", …
## $ article_chapter_link <list> "", "", "", "", "", "", "", "", "", "", "", "", …
## $ isbns                <list> [["0063061198", "9780063061194"], ["006306121X",…
## $ buy_links            <list> [["Amazon", "https://www.amazon.com/dp/006306119…
## $ book_uri             <list> "nyt://book/2641ab34-1d1b-570d-81dc-ca874279ea5a…

Some of these variables don’t provide us with much information, so I subset the data frame.

bookInfoDFSubset <- bookInfoDF |> select(rank, rank_last_week, weeks_on_list,
                                         primary_isbn10, primary_isbn13, publisher,
                                         description, title, author,
                                         contributor)

glimpse(bookInfoDFSubset)
## Rows: 15
## Columns: 10
## $ rank           <list> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
## $ rank_last_week <list> 2, 4, 1, 3, 0, 5, 6, 0, 7, 8, 0, 12, 0, 0, 0
## $ weeks_on_list  <list> 3, 51, 2, 47, 1, 15, 3, 1, 2, 3, 34, 75, 17, 1, 1
## $ primary_isbn10 <list> "0063061198", "0593236599", "0063263904", "0385534264"…
## $ primary_isbn13 <list> "9780063061194", "9780593236598", "9780063263901", "97…
## $ publisher      <list> "Harper", "Harmony", "Dey Street", "Doubleday", "Farra…
## $ description    <list> "The author of “Red-Handed” depicts a scheme involving…
## $ title          <list> "BLOOD MONEY", "OUTLIVE", "THE HOUSE OF HIDDEN MEANING…
## $ author         <list> "Peter Schweizer", "Peter Attia with Bill Gifford", "R…
## $ contributor    <list> "by Peter Schweizer", "by Peter Attia with Bill Giffor…

Below I clean up the data frame

bookInfoDFSubset <- bookInfoDFSubset |>
  mutate(across(c(rank, rank_last_week, weeks_on_list), as.numeric),
         across(c(primary_isbn10, primary_isbn13, publisher, description,
                  title, author, contributor), as.character))

head(bookInfoDFSubset)
##   rank rank_last_week weeks_on_list primary_isbn10 primary_isbn13
## 1    1              2             3     0063061198  9780063061194
## 2    2              4            51     0593236599  9780593236598
## 3    3              1             2     0063263904  9780063263901
## 4    4              3            47     0385534264  9780385534260
## 5    5              0             1     0374299404  9780374299408
## 6    6              5            15     0316572063  9780316572064
##                 publisher
## 1                  Harper
## 2                 Harmony
## 3              Dey Street
## 4               Doubleday
## 5 Farrar, Straus & Giroux
## 6           Little, Brown
##                                                                                                                                               description
## 1                                       The author of “Red-Handed” depicts a scheme involving the Chinese Communist Party’s covert operations in America.
## 2                                                                                            A look at recent scientific research on aging and longevity.
## 3     The multiple Emmy Award-winning producer of “RuPaul’s Drag Race” traces his journey from his childhood in San Diego to becoming a pop culture icon.
## 4                  The survivors of a shipwrecked British vessel on a secret mission during an imperial war with Spain have different accounts of events.
## 5                                               The Pulitzer Prize-winning author of “Gilead” illuminates the literary aspects of the Bible’s first book.
## 6 The former congresswoman from Wyoming recounts how she helped lead the Select Committee to Investigate the Jan. 6. Attack on the United States Capitol.
##                          title                        author
## 1                  BLOOD MONEY               Peter Schweizer
## 2                      OUTLIVE Peter Attia with Bill Gifford
## 3 THE HOUSE OF HIDDEN MEANINGS                        RuPaul
## 4                    THE WAGER                   David Grann
## 5              READING GENESIS            Marilynne Robinson
## 6               OATH AND HONOR                    Liz Cheney
##                        contributor
## 1               by Peter Schweizer
## 2 by Peter Attia with Bill Gifford
## 3                        by RuPaul
## 4                   by David Grann
## 5            by Marilynne Robinson
## 6                    by Liz Cheney
glimpse(bookInfoDFSubset)
## Rows: 15
## Columns: 10
## $ rank           <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
## $ rank_last_week <dbl> 2, 4, 1, 3, 0, 5, 6, 0, 7, 8, 0, 12, 0, 0, 0
## $ weeks_on_list  <dbl> 3, 51, 2, 47, 1, 15, 3, 1, 2, 3, 34, 75, 17, 1, 1
## $ primary_isbn10 <chr> "0063061198", "0593236599", "0063263904", "0385534264",…
## $ primary_isbn13 <chr> "9780063061194", "9780593236598", "9780063263901", "978…
## $ publisher      <chr> "Harper", "Harmony", "Dey Street", "Doubleday", "Farrar…
## $ description    <chr> "The author of “Red-Handed” depicts a scheme involving …
## $ title          <chr> "BLOOD MONEY", "OUTLIVE", "THE HOUSE OF HIDDEN MEANINGS…
## $ author         <chr> "Peter Schweizer", "Peter Attia with Bill Gifford", "Ru…
## $ contributor    <chr> "by Peter Schweizer", "by Peter Attia with Bill Gifford…

The data frame is now clean and it is in tidy format. Each row is an observation, in this case a book, and each column is a variable that captures information about the book: its rank on the list, its rank on the list last week,…, title, author, and contributor.