making the api request and storing the results in a dataframe
# Define the API URL with your specific endpoint and parameters
api_url <- "https://api.nytimes.com/svc/books/v3/lists/best-sellers/history.json?api-key=8GkfuqeNdp08Sc1RtvRSxCP6DDwHgkof"
# Make a GET request to the API
response <- GET(api_url)
json_data <- content(response, "text")
json_object <- fromJSON(json_data)
best_seller <- json_object$results
head(best_seller)
## title
## 1 "I GIVE YOU MY BODY ..."
## 2 "MOST BLESSED OF THE PATRIARCHS"
## 3 "YOU JUST NEED TO LOSE WEIGHT"
## 4 #ASKGARYVEE
## 5 #GIRLBOSS
## 6 #IMOMSOHARD
## description
## 1 The author of the Outlander novels gives tips on writing sex scenes, drawing on examples from the books.
## 2 A character study that attempts to make sense of Jefferson’s contradictions.
## 3 The co-host of the podcast “Maintenance Phase” examines myths about gaining and losing weight to dismantle anti-fat bias.
## 4 The entrepreneur expands on subjects addressed on his Internet show, like marketing, management and social media.
## 5 An online fashion retailer traces her path to success.
## 6
## contributor author
## 1 by Diana Gabaldon Diana Gabaldon
## 2 by Annette Gordon-Reed and Peter S. Onuf Annette Gordon-Reed and Peter S Onuf
## 3 by Aubrey Gordon Aubrey Gordon
## 4 by Gary Vaynerchuk Gary Vaynerchuk
## 5 by Sophia Amoruso Sophia Amoruso
## 6 by Kristin Hensley and Jen Smedley Kristin Hensley and Jen Smedley
## contributor_note price age_group publisher
## 1 0.00 Dell
## 2 0.00 Liveright
## 3 0.00 Beacon
## 4 0.00 HarperCollins
## 5 0.00 Portfolio/Penguin/Putnam
## 6 0.00 HarperOne
## isbns
## 1 0399178570, 9780399178573
## 2 0871404427, 9780871404428
## 3 0807006475, 0807006483, 9780807006474, 9780807006481
## 4 0062273124, 0062273132, 9780062273123, 9780062273130
## 5 039916927X, 1591847931, 9780399169274, 9781591847939
## 6 006285769X, 9780062857699
## ranks_history
## 1 0399178570, 9780399178573, 8, Advice How-To and Miscellaneous, Advice, How-To & Miscellaneous, 2016-09-04, 2016-08-20, 1, 0, 0, 0
## 2 0871404427, 9780871404428, 16, Hardcover Nonfiction, Hardcover Nonfiction, 2016-05-01, 2016-04-16, 1, 0, 1, 0
## 3 0807006475, 0807006475, 9780807006474, 9780807006474, 2, 6, Paperback Nonfiction, Combined Print and E-Book Nonfiction, Paperback Nonfiction, Combined Print & E-Book Nonfiction, 2023-01-29, 2023-01-29, 2023-01-14, 2023-01-14, 1, 1, 0, 0, 0, 0, 0, 0
## 4 0062273124, 0062273124, 9780062273123, 9780062273123, 5, 6, Business Books, Advice How-To and Miscellaneous, Business, Advice, How-To & Miscellaneous, 2016-04-10, 2016-03-27, 2016-03-26, 2016-03-12, 0, 1, 0, 0, 0, 0, 1, 1
## 5 1591847931, 1591847931, 1591847931, 1591847931, 039916927X, 9781591847939, 9781591847939, 9781591847939, 9781591847939, 9780399169274, 8, 9, 9, 8, 10, Business Books, Business Books, Business Books, Business Books, Business Books, Business, Business, Business, Business, Business, 2016-03-13, 2016-01-17, 2015-12-13, 2015-11-15, 2014-11-09, 2016-02-27, 2016-01-02, 2015-11-28, 2015-10-31, 2014-10-25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
## 6 006285769X, 9780062857699, 10, Advice How-To and Miscellaneous, Advice, How-To & Miscellaneous, 2019-04-21, 2019-04-06, 1, 0, 0, 1
## reviews
## 1 , , ,
## 2 , , ,
## 3 , , ,
## 4 , , ,
## 5 , , ,
## 6 , , ,
just store the data without the na in it
# Assuming 'best_seller' is your original DataFrame
# Create a new DataFrame without NAs
cleaned_best_seller <- na.omit(best_seller)