Introduction

This assignment was to read in JSON data from one of NY Times APIs and turn into a dataframe. I decide to use the Article Search API to look up articles about Queen Elizabeth from the day of her death to the end of that year.

The first step is to call the necessary libraries.

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
library(httr)
library(jsonlite)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(stringr)

Get articles

In order to get these articles, I needed to sign up for an API key which I then saved as a variable. I also saved my search term/word (Queen), and the two dates I would like to find articles in between. Combined, this creates the search url that will be used.

apiKey <- "hSndMn20mNAgN0TcTP20NOY4Xc01dtuP"
term <- "Queen"
subsection <- "Europe"
begin_date <- "20220908"
end_date <- "20221231"

searchUrl <- paste0("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=",term,
                  "&fq=subsection_name:",subsection,
                  "&begin_date=",begin_date,
                  "&end_date=",end_date,
                  "&facet_filter=true&api-key=",apiKey, 
                  sep="")

Next was to execute the search url that results in an query and this gives us a raw/unorganized query of articles. Using a for loop, we separate the articles into their own rows in dataframe, articles. Articles still prints out messy as there are a lot of columns and information that the search query gives that is unnecessary.

searchQuery <- fromJSON(searchUrl)
maxPages <- round((searchQuery$response$meta$hits[1] / 10)-1) 
pages <- vector("list",length=maxPages)
for(i in 0:maxPages){
  nytSearch <- fromJSON(paste0(searchUrl, "&page=", i), flatten = TRUE) %>% data.frame()
  pages[[i+1]] <- nytSearch
  Sys.sleep(5)
}
## Error in open.connection(con, "rb"): cannot open the connection to 'http://api.nytimes.com/svc/search/v2/articlesearch.json?q=Queen&fq=subsection_name:Europe&begin_date=20220908&end_date=20221231&facet_filter=true&api-key=hSndMn20mNAgN0TcTP20NOY4Xc01dtuP&page=4'
articles <- rbind_pages(pages)
head(articles, 1)
##   status                                                           copyright
## 1     OK Copyright (c) 2023 The New York Times Company. All Rights Reserved.
##                                                                                                                           response.docs.abstract
## 1 Pound notes with the new sovereign’s image will begin appearing in 2024, though money with his mother’s likeness will still be in circulation.
##                                                        response.docs.web_url
## 1 https://www.nytimes.com/2022/12/19/world/europe/king-charles-money-uk.html
##                                                                                                                            response.docs.snippet
## 1 Pound notes with the new sovereign’s image will begin appearing in 2024, though money with his mother’s likeness will still be in circulation.
##                                                                                                                              response.docs.lead_paragraph
## 1 LONDON — In recent months, as Britain has healed from mourning its queen, the beginning of a new reign has started to show in the country’s daily life.
##   response.docs.print_section response.docs.print_page response.docs.source
## 1                           A                        9   The New York Times
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              response.docs.multimedia
## 1 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, xlarge, popup, blog480, blog533, blog427, tmagSF, tmagArticle, slide, jumbo, superJumbo, blog225, master1050, master675, master495, master180, master315, master768, thumbnail, blogSmallThumb, thumbLarge, smallSquare168, smallSquare252, square320, moth, filmstrip, square640, mediumSquare149, mediumSquareAt3X, sfSpan, largeHorizontal375, largeHorizontalJumbo, horizontalMediumAt2X, hpLarge, largeWidescreen573, largeWidescreen1050, wide, videoThumb, videoLarge, mediumThreeByTwo210, mediumThreeByTwo225, mediumThreeByTwo440, mediumThreeByTwo252, mediumThreeByTwo378, threeByTwoLargeAt2X, threeByTwoMediumAt2X, threeByTwoSmallAt2X, articleInline, hpSmall, blogSmallInline, mediumFlexible177, videoSmall, videoHpMedium, videoSixteenByNine600, videoSixteenByNine540, videoSixteenByNine495, videoSixteenByNine390, videoSixteenByNine1050, videoSixteenByNine480, videoSixteenByNine310, videoSixteenByNine225, videoSixteenByNine96, videoSixteenByNine768, videoSixteenByNine150, videoSixteenByNineJumbo1600, miniMoth, windowsTile336H, facebookJumbo, watch308, watch268, mobileMasterAt3x, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, image, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-articleLarge.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-popup.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-blog480.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-blog533.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-blog427.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-tmagSF.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-tmagArticle.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-slide.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-jumbo.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-superJumbo.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-blog225.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-master1050.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-master675.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-master495.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-master180.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-master315.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-master768.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-thumbStandard.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-blogSmallThumb.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-thumbLarge.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-smallSquare168.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-smallSquare252.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-square320.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-moth.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-filmstrip.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-square640.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumSquare149.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumSquareAt3X.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-sfSpan.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-largeHorizontal375.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-largeHorizontalJumbo.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-horizontalMediumAt2X.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-hpLarge.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-largeWidescreen573.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-largeWidescreen1050.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-thumbWide.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoThumb.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoLarge.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumThreeByTwo210.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumThreeByTwo225.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumThreeByTwo440.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumThreeByTwo252.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumThreeByTwo378.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-threeByTwoLargeAt2X.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-threeByTwoMediumAt2X.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-threeByTwoSmallAt2X.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-articleInline.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-hpSmall.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-blogSmallInline.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mediumFlexible177.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSmall.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoHpMedium.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine600.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine540.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine495.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine390.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine1050.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine480.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine310.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine225.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine96.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine768.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNine150.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-videoSixteenByNineJumbo1600.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-miniMoth.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-windowsTile336H.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-facebookJumbo.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-watch308.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-watch268.png, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-mobileMasterAt3x.png, 400, 434, 320, 356, 285, 242, 395, 400, 683, 782, 150, 701, 450, 330, 120, 210, 512, 75, 50, 150, 168, 252, 320, 151, 190, 640, 149, 834, 264, 250, 683, 782, 287, 322, 591, 126, 50, 507, 140, 150, 293, 168, 252, 782, 782, 400, 127, 109, 101, 118, 281, 211, 338, 304, 278, 219, 591, 270, 174, 126, 54, 432, 84, 660, 70, 336, 550, 348, 304, 764, 600, 650, 480, 533, 427, 362, 592, 600, 1024, 1172, 225, 1050, 675, 495, 180, 315, 768, 75, 50, 150, 168, 252, 320, 151, 190, 640, 149, 834, 395, 375, 1024, 1172, 511, 573, 1050, 190, 75, 768, 210, 225, 440, 252, 378, 1172, 1172, 600, 190, 163, 151, 177, 500, 375, 600, 540, 495, 390, 1050, 480, 310, 225, 96, 768, 150, 1172, 151, 694, 1050, 312, 272, 956, xlarge, popup, blog480, blog533, blog427, tmagSF, tmagArticle, slide, jumbo, superJumbo, blog225, master1050, master675, master495, master180, master315, master768, thumbnail, blogSmallThumb, thumbLarge, smallSquare168, smallSquare252, square320, moth, filmstrip, square640, mediumSquare149, mediumSquareAt3X, sfSpan, largeHorizontal375, largeHorizontalJumbo, horizontalMediumAt2X, hpLarge, largeWidescreen573, largeWidescreen1050, wide, videoThumb, videoLarge, mediumThreeByTwo210, mediumThreeByTwo225, mediumThreeByTwo440, mediumThreeByTwo252, mediumThreeByTwo378, threeByTwoLargeAt2X, threeByTwoMediumAt2X, threeByTwoSmallAt2X, articleInline, hpSmall, blogSmallInline, mediumFlexible177, videoSmall, videoHpMedium, videoSixteenByNine600, videoSixteenByNine540, videoSixteenByNine495, videoSixteenByNine390, videoSixteenByNine1050, videoSixteenByNine480, videoSixteenByNine310, videoSixteenByNine225, videoSixteenByNine96, videoSixteenByNine768, videoSixteenByNine150, videoSixteenByNineJumbo1600, miniMoth, windowsTile336H, facebookJumbo, watch308, watch268, mobileMasterAt3x, articleLarge, popup, blog480, blog533, blog427, tmagSF, tmagArticle, slide, jumbo, superJumbo, blog225, master1050, master675, master495, master180, master315, master768, thumbStandard, blogSmallThumb, thumbLarge, smallSquare168, smallSquare252, square320, moth, filmstrip, square640, mediumSquare149, mediumSquareAt3X, sfSpan, largeHorizontal375, largeHorizontalJumbo, horizontalMediumAt2X, hpLarge, largeWidescreen573, largeWidescreen1050, thumbWide, videoThumb, videoLarge, mediumThreeByTwo210, mediumThreeByTwo225, mediumThreeByTwo440, mediumThreeByTwo252, mediumThreeByTwo378, threeByTwoLargeAt2X, threeByTwoMediumAt2X, threeByTwoSmallAt2X, articleInline, hpSmall, blogSmallInline, mediumFlexible177, videoSmall, videoHpMedium, videoSixteenByNine600, videoSixteenByNine540, videoSixteenByNine495, videoSixteenByNine390, videoSixteenByNine1050, videoSixteenByNine480, videoSixteenByNine310, videoSixteenByNine225, videoSixteenByNine96, videoSixteenByNine768, videoSixteenByNine150, videoSixteenByNineJumbo1600, miniMoth, windowsTile336H, facebookJumbo, watch308, watch268, mobileMasterAt3x, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-articleLarge.png, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 600, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 400, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-thumbStandard.png, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 75, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 75, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 190, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 126, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, images/2022/12/20/world/19uk-cash-print/king-charles-banknotes-02-thumbWide.png, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
##                                                                                                                                                                                                                                                                                                                                                                                                          response.docs.keywords
## 1 persons, subject, subject, subject, subject, subject, subject, organizations, organizations, persons, Charles III, King of the United Kingdom, Currency, British Pound (Currency), Politics and Government, International Relations, Numismatics, Banking and Financial Institutions, Bank of England, Royal Mint Ltd, The, Elizabeth II, Queen of Great Britain, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, N, N, N, N, N, N, N, N, N, N
##     response.docs.pub_date response.docs.document_type response.docs.news_desk
## 1 2022-12-20T00:00:10+0000                     article                 Foreign
##   response.docs.section_name response.docs.subsection_name
## 1                      World                        Europe
##   response.docs.type_of_material
## 1                           News
##                                    response.docs._id response.docs.word_count
## 1 nyt://article/d5b316a1-c136-5d49-9a05-0ad9fc581093                      471
##                                    response.docs.uri
## 1 nyt://article/d5b316a1-c136-5d49-9a05-0ad9fc581093
##                      response.docs.headline.main response.docs.headline.kicker
## 1 King Charles III Is the New Face of U.K. Money                          <NA>
##   response.docs.headline.content_kicker
## 1                                    NA
##        response.docs.headline.print_headline response.docs.headline.name
## 1 King Charles III Will Be on New U.K. Bills                          NA
##   response.docs.headline.seo response.docs.headline.sub
## 1                         NA                         NA
##   response.docs.byline.original             response.docs.byline.person
## 1                By Emma Bubola Emma, NA, Bubola, NA, NA, reported, , 1
##   response.docs.byline.organization response.meta.hits response.meta.offset
## 1                              <NA>                139                    0
##   response.meta.time
## 1                 29

Cleaning/Tidying the dataframe

After getting articles as a raw dataframe, I cleaned up the column names a bit. I then determined which columns I would want to keep as some had irrelevant data or no data (NA). The selected columns were then subsetted into a new dataframe, queenArticles, that acts as our final dataframe after doing some column renaming.

colnames(articles)
##  [1] "status"                               
##  [2] "copyright"                            
##  [3] "response.docs.abstract"               
##  [4] "response.docs.web_url"                
##  [5] "response.docs.snippet"                
##  [6] "response.docs.lead_paragraph"         
##  [7] "response.docs.print_section"          
##  [8] "response.docs.print_page"             
##  [9] "response.docs.source"                 
## [10] "response.docs.multimedia"             
## [11] "response.docs.keywords"               
## [12] "response.docs.pub_date"               
## [13] "response.docs.document_type"          
## [14] "response.docs.news_desk"              
## [15] "response.docs.section_name"           
## [16] "response.docs.subsection_name"        
## [17] "response.docs.type_of_material"       
## [18] "response.docs._id"                    
## [19] "response.docs.word_count"             
## [20] "response.docs.uri"                    
## [21] "response.docs.headline.main"          
## [22] "response.docs.headline.kicker"        
## [23] "response.docs.headline.content_kicker"
## [24] "response.docs.headline.print_headline"
## [25] "response.docs.headline.name"          
## [26] "response.docs.headline.seo"           
## [27] "response.docs.headline.sub"           
## [28] "response.docs.byline.original"        
## [29] "response.docs.byline.person"          
## [30] "response.docs.byline.organization"    
## [31] "response.meta.hits"                   
## [32] "response.meta.offset"                 
## [33] "response.meta.time"
colnames(articles) <- str_replace(colnames(articles),pattern='response.docs\\.',replace='')
colnames(articles) <- str_replace(colnames(articles),pattern='response\\.',replace='')
colnames(articles)
##  [1] "status"                  "copyright"              
##  [3] "abstract"                "web_url"                
##  [5] "snippet"                 "lead_paragraph"         
##  [7] "print_section"           "print_page"             
##  [9] "source"                  "multimedia"             
## [11] "keywords"                "pub_date"               
## [13] "document_type"           "news_desk"              
## [15] "section_name"            "subsection_name"        
## [17] "type_of_material"        "_id"                    
## [19] "word_count"              "uri"                    
## [21] "headline.main"           "headline.kicker"        
## [23] "headline.content_kicker" "headline.print_headline"
## [25] "headline.name"           "headline.seo"           
## [27] "headline.sub"            "byline.original"        
## [29] "byline.person"           "byline.organization"    
## [31] "meta.hits"               "meta.offset"            
## [33] "meta.time"
queenArticles<-as.data.frame(articles)

#columns to keep: copyright,web_url,pub_date,type_of_material,word_count,headline.main,byline.original
queenArticles <- subset(queenArticles, select=c(2,4,12,16,18,21,28))

colnames(queenArticles)[3]="publish_date"
colnames(queenArticles)[4]="type_of_article"
colnames(queenArticles)[6]="headline"
colnames(queenArticles)[7]="original_author"

kable(queenArticles, "html") %>% kable_styling("striped") %>% scroll_box(width = "100%")
copyright web_url publish_date type_of_article _id headline original_author
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/12/19/world/europe/king-charles-money-uk.html 2022-12-20T00:00:10+0000 Europe nyt://article/d5b316a1-c136-5d49-9a05-0ad9fc581093 King Charles III Is the New Face of U.K. Money By Emma Bubola
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/12/15/world/europe/prince-harry-william-meghan-netflix.html 2022-12-15T18:58:54+0000 Europe nyt://article/4ff17a70-a7a9-52c8-a362-3be50981e29b Harry Takes Aim at William in New Episodes of Netflix Documentary By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/11/30/world/europe/buckingham-palace-black-guest.html 2022-11-30T15:46:48+0000 Europe nyt://article/462266a1-e175-5091-89e1-7d8662fc6ab0 Buckingham Palace Staff Member Resigns Over Remarks to Black Guest By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/18/world/europe/queen-elizabeth-biden.html 2022-09-18T22:10:10+0000 Europe nyt://article/062e17f8-1dda-5f50-a9e6-685701da8fc6 Biden Pays Homage to Queen Elizabeth, Calling the Monarch ‘Decent, Honorable’ By Zolan Kanno-Youngs
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/10/25/world/europe/uk-king-charles-rishi-sunak.html 2022-10-25T09:32:09+0000 Europe nyt://article/b9c9d44d-ede2-5699-8391-e8f0d7b3649f A familiar British ritual now features two new participants. By Peter Robins
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/14/world/europe/queen-funeral-costs.html 2022-09-14T16:55:11+0000 Europe nyt://article/e719f256-93d8-5336-89ae-093476ce7e6e The queen’s funeral will be paid for by British taxpayers. By Jenny Gross
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/09/world/europe/queen-elizabeth-women.html 2022-09-09T17:10:13+0000 Europe nyt://article/ec249eb0-45e3-5f56-bf80-3233a7537c4a Queen Elizabeth, and the Power and Limitations of Inspiring Women By Amanda Taub
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/09/world/europe/queen-elizabeth-britain-monarchy.html 2022-09-09T07:00:06+0000 Europe nyt://article/3f417f32-2aa9-5438-804f-5d91039f0449 Queen Elizabeth II: The One Constant in an Inconstant World By Sarah Lyall
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/10/14/world/europe/netherlands-princess-threats-university.html 2022-10-14T16:46:05+0000 Europe nyt://article/bed56189-467f-509b-8dc1-a9b3a52414eb Dutch Princess ‘Can’t Really Go Outside’ After Threats By Claire Moses
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/10/05/world/europe/denmark-queen-royal-titles-apology.html 2022-10-05T18:41:21+0000 Europe nyt://article/bcbdb8b1-b7cc-551a-a942-c0ef3b8ad411 Danish Queen Apologizes After Stripping Royal Titles From 4 Grandchildren By Johnny Diaz
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/29/world/europe/queen-elizabeth-death-time.html 2022-09-29T15:10:03+0000 Europe nyt://article/b2969903-53b7-5d69-a199-96e30f30f2d0 Queen’s Death Certificate Reveals Cause and Time of Death By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-elizabeth-funeral-coronation.html 2022-09-19T17:50:49+0000 Europe nyt://article/bd2e0e13-1c04-5152-a08d-8da4e9940554 From Coronation to Funeral: Bookends to the Life of a Queen, and a Generation By Alan Cowell
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-elizabeth-funeral-how-to-watch.html 2022-09-19T05:33:19+0000 Europe nyt://article/ad2ef614-62c4-500d-9443-6588b319484a How to watch the queen’s funeral. By Emma Bubola
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-funeral-guest-list.html 2022-09-19T05:01:33+0000 Europe nyt://article/1ee1ee4e-454d-541d-97d1-b27c7934de40 The guest list for the queen’s funeral will include presidents and an emperor. By The New York Times
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/interactive/2022/09/19/world/europe/queen-funeral-order-of-service.html 2022-09-19T10:48:23+0000 Europe nyt://interactive/0e2bdae8-2396-553d-9325-4d690f04da73 Read the Order of Service for Queen Elizabeth II’s State Funeral NA
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-funeral-windsor-crowd.html 2022-09-19T11:37:56+0000 Europe nyt://article/d2cc5abc-ff71-5d88-a430-1a773c619d3e Crowds gather in Windsor as they await the arrival of the queen’s coffin from London. By Stephen Castle
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-elizabeth-burial-site-windsor.html 2022-09-19T10:54:48+0000 Europe nyt://article/d0305fb1-842b-5b6b-ae95-1b947f5c031d At Windsor, the queen will be interred with her husband, who died last year. By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-funeral-public-service-guests.html 2022-09-18T20:25:29+0000 Europe nyt://article/55061331-398c-5dfb-9fac-2a9568a17193 Guest List for Queen Elizabeth’s Funeral Includes Everyday Honorees By Emma Bubola
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-elizabeth-funeral-hyde-park.html 2022-09-19T12:00:01+0000 Europe nyt://article/9fbab205-8394-5de3-9203-2dc0be034ff5 ‘They don’t make them like her anymore’: A crowd in Hyde Park bids goodbye to the queen. By Emma Bubola
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/17/world/europe/queen-elizabeth-william-harry-queue.html 2022-09-17T17:54:55+0000 Europe nyt://article/bd96d89c-7ec1-52df-a375-1dbe538a49bc Britons Undeterred by Daylong Waits to Mourn a Queen They Loved By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-elizabeth-funeral.html 2022-09-19T21:14:20+0000 Europe nyt://article/974aa4c6-8184-59ed-950d-c4735ac0e52b Thousands Pay Tribute as Britain Says Final Farewell to Its Queen By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-elizabeth-funeral-windsor-castle.html 2022-09-19T19:00:15+0000 Europe nyt://article/5695fb21-f108-5b2b-969b-7a07c4f895e2 Windsor, Queen’s Final Resting Place, Has a Long Association With Her By Stephen Castle
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/19/world/europe/queen-funeral-crowds.html 2022-09-19T18:56:18+0000 Europe nyt://article/95cc9165-e4cf-5137-8488-5d342adce9b3 In Parks and on Post Boxes, Crowds Say Farewell to the Queen By Megan Specia
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/interactive/2022/09/15/world/europe/queen-elizabeth-queue-line.html 2022-09-15T16:24:33+0000 Europe nyt://interactive/dad1ec69-db60-5732-beb6-b5ddec25528c The Overnight Wait to See the Queen By Isabella Kwai
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/18/world/europe/aberfan-wales-queen-elizabeth-funeral.html 2022-09-18T09:00:27+0000 Europe nyt://article/8bbada66-014a-5956-8dc2-e1f9d8b6ad36 A Welsh Village Embraces Its Bond With the Queen By Patrick Kingsley and Mary Turner
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/video/world/europe/100000008538285/queen-queue.html 2022-09-16T16:54:41+0000 Europe nyt://video/e5c51e70-93ae-5b41-8349-5b421b185312 Line to See Queen Elizabeth’s Coffin Reaches 5 Miles By The Associated Press and Reuters
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/interactive/2022/09/13/world/europe/queen-elizabeth-whats-next.html 2022-09-13T20:09:30+0000 Europe nyt://interactive/1531e49a-08ea-5e87-8bf3-cf5ba7d016a2 The Queen’s Journey Home By Yonette Joseph
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/12/world/europe/monty-roberts-queen.html 2022-09-12T15:16:34+0000 Europe nyt://article/0aea4ec5-f267-5797-a47f-3219b8a0e3cb The Cowboy and the Queen By Jenny Gross
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/video/world/europe/100000008535751/queen-elizabeth-viewing-lines.html 2022-09-15T14:35:48+0000 Europe nyt://video/5355412b-96a3-5380-82c0-b3126a77600e Mourners Wait Overnight to Pay Respects to Queen Elizabeth II By The Associated Press
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/14/world/europe/queen-elizabeth-funeral-procession-london.html 2022-09-14T19:30:29+0000 Europe nyt://article/182dd5a4-32c1-5f2e-8f02-8cb8ca2a93ae Queen’s Coffin Passes London Landmarks, in a Grand but Hushed Royal Display By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/15/world/europe/queen-elizabeth-funeral.html 2022-09-15T19:33:15+0000 Europe nyt://article/f23d512a-648b-515c-b00d-48a4df1942f6 A Detailed Rundown of Queen Elizabeth’s Funeral Day By Emma Bubola
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/video/world/europe/100000008534069/queen-elizabeth-london-procession.html 2022-09-14T17:25:15+0000 Europe nyt://video/fd2ddf25-d851-5621-b7c2-62f3c7969137 Queen Elizabeth II’s Coffin Is Carried to Westminster Hall By Reuters
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/16/world/europe/queen-queue.html 2022-09-16T10:53:31+0000 Europe nyt://article/a9032345-d694-5516-b270-d34cfb1a9b86 After Temporary Break, Line to View Queen’s Coffin Is Reopened By Isabella Kwai
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/article/queen-funeral-schedule.html 2022-09-12T20:49:33+0000 Europe nyt://article/ebfb9efe-129c-5160-9660-d5f9c73eb2b2 What to expect as Britain mourns the queen. By Mark Landler
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/14/world/europe/queen-elizabeth-coffin-procession-timing.html 2022-09-14T11:48:41+0000 Europe nyt://article/f89d1c51-b369-5344-9c2b-95e8311446d1 The queen’s coffin will leave Buckingham Palace at exactly 2:22 p.m. By Isabella Kwai
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/14/world/europe/queen-elizabeth-queen-margrethe.html 2022-09-14T10:44:15+0000 Europe nyt://article/b024ffbd-e914-5523-8e40-69bc30ae5dfd A Danish royal who mourns her friend ‘Lilibet’ is now the reigning queen in Europe. By Yonette Joseph
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/11/world/europe/queen-elizabeth-corgis.html 2022-09-11T20:23:52+0000 Europe nyt://article/386e4854-8e7c-5a6a-bea1-d1b0efb564aa Queen Elizabeth’s Corgis Will Stay in the Family By Yonette Joseph
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/15/world/europe/queen-lying-in-state-queue.html 2022-09-15T09:57:17+0000 Europe nyt://article/6692e56e-a318-575c-97d9-0fe1ac632d57 ‘We’re Part of History’: An Overnight Wait to Bid Farewell to Queen Elizabeth II By Isabella Kwai
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/2022/09/11/world/europe/queen-scotland-independence.html 2022-09-11T19:32:22+0000 Europe nyt://article/5696c6e3-de9c-5b77-9bdc-8e150e2b5c5f Queen’s Ties to Scotland Add New Wrinkle to Push for Independence By Stephen Castle
Copyright (c) 2023 The New York Times Company. All Rights Reserved. https://www.nytimes.com/video/world/europe/100000008529868/queen-elizabeth-edinburgh-procession.html 2022-09-12T17:33:59+0000 Europe nyt://video/21dc490f-75fb-5240-a8e9-44a680d3260c Crowds Line Streets to Mourn Queen Elizabeth II in Edinburgh By The Associated Press

With this, the data/articles collected using NY Times Article Search API is cleaned and ready for analysis.