- Download necessary packages.
suppressWarnings(suppressMessages(library(knitr)))
suppressWarnings(suppressMessages(library(jsonlite)))
suppressWarnings(suppressMessages(library(httr)))
suppressWarnings(suppressMessages(library(pander)))
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(tidyr)))
suppressWarnings(suppressMessages(library(stringr)))
- Get New York Times API Key
api_key<-"f9c3067b7adb4ae08ab5b1c86913e1fd"
- Get a URL
page_url<-GET(paste("http://api.nytimes.com/svc/topstories/v1/home.json?&api-key=",api_key,sep = ""))
- Extract content from a request.
json_data <- content(page_url,encoding = "UTF-8")
- Read json file.
json <- fromJSON(json_data)
- Importing data from JSON file into R data frame.
data_frame <- as.data.frame(json$results)
- Cleaning data frame.
data_frame %>% select(-kicker,-des_facet,-org_facet,-per_facet,-geo_facet,-multimedia) %>% separate(updated_date, c("updated_date", "updated_time"),sep = "T") %>% separate(created_date, c("created_date", "created_time"),sep = "T") %>% separate(published_date, c("published_date", "published_time"),sep = "T") %>% mutate(byline = str_replace(byline, "By ", "")) %>% mutate(created_time = str_replace(created_time, "-5:00", "")) %>% mutate(published_time = str_replace(published_time, "-5:00", "")) %>% mutate(updated_time = str_replace(updated_time, "-5:00", ""))
## section subsection
## 1 Business Day Energy & Environment
## 2 U.S. Politics
## 3 U.S. Politics
## 4 U.S. Politics
## 5 Business Day
## 6 U.S. Politics
## 7 U.S.
## 8 U.S.
## 9 U.S.
## 10 U.S. Politics
## 11 World Africa
## 12 Business Day
## 13 World Middle East
## 14 World Europe
## 15 Briefing
## 16 Sports
## 17 U.S. Politics
## 18 World Asia Pacific
## 19 Business Day
## 20 N.Y. / Region
## 21 World Australia
## 22 World Australia
## 23 Food
## 24 Arts Dance
## 25 Books Book Review
## 26 Sports
## title
## 1 Russia Wields Oil Diplomacy, Pushing In on U.S. Interests
## 2 Trump Tries to Shift Focus Amid Reports of Looming Charges
## 3 Twitter Suspends Roger Stone After Expletive-Laden Posts
## 4 ‘Bedlam’ in Arizona After Jeff Flake Departs Senate Race
## 5 Limit on 401(k) Savings? It’s About Paying for Tax Cuts
## 6 Democrats Attack Tax Bill as a ‘Middle-Class Con Job’
## 7 Puerto Rico Cancels Grid Contract With Small Montana Firm
## 8 Sexual Misconduct in California Capitol Is Difficult to Escape
## 9 Rose McGowan, Refusing Weinstein’s Hush Money, Speaks Out
## 10 2 Navy SEALs Under Suspicion in Death of Green Beret in Mali
## 11 In Niger, Where U.S. Troops Died, a Lawless and Shifting Landscape
## 12 In Choice of Fed Chairman, Trump Downgrades Deregulation
## 13 Egypt Shakes Up Security Forces After Deadly Ambush of Police
## 14 Iceland’s Governing Party Retains Most Seats
## 15 Your Monday Briefing
## 16 Live Updates: Dodgers and Astros Meet for Game 5
## 17 F.B.I. Agents in Legal Ordeal Over Fertility Treatment
## 18 Troubling Turn in Afghan War: Taliban Heroin Profits Soar
## 19 Facebook’s Most Disturbing Problems Are Abroad
## 20 A Revered New York Priest Is Named a Predator
## 21 Australian Government Rejects Move for Indigenous ‘Recognition’
## 22 Australia Deputy Leader Among 5 to Lose Seats Over Citizenship
## 23 Japanese and Australian Foodways Mix Off a Winding Road
## 24 Review: All Life Is a Swirl in ‘The Red Shoes’
## 25 Ron Chernow: Marinating in Postbellum America
## 26 N.F.L. Updates: Texans Kneel During Anthem
## abstract
## 1 Moscow, forced by sanctions to find new spheres of investment, is building influence in places where the United States has stumbled. It has been pushing deeply into countries like Cuba, China, Egypt and Vietnam, and has made a flurry of risky loans to help Venezuela stave off debt default.
## 2 President Trump attacked Hillary Clinton on Twitter as he and his advisers braced for the first public action from the special prosecutor in the Russia inquiry, who is reportedly poised to issue an indictment.
## 3 The longtime supporter of President Trump lobbed insults at CNN anchors and contributors, leading to a suspension of his Twitter account.
## 4 The Republican senator’s surprise announcement not to run for re-election has created a frantic race for his seat and opened divisions in both major parties.
## 5 “This is not a retirement security story,” a tax expert says. It’s about finding revenue to pay for reductions in business taxes sooner rather than later.
## 6 Democrats hope to turn back a Republican bill, painting it as a windfall for business and the rich, and instead work with President Trump on bipartisan legislation.
## 7 The move came after members of Congress and FEMA expressed concerns about how Whitefish Energy won a contract for up to $300 million to rebuild part of the island’s hurricane-ravaged electrical grid.
## 8 Women in Sacramento complain of a culture of rampant harassment and of a system that does not seriously address their complaints.
## 9 Rose McGowan, who has said that Harvey Weinstein sexually assaulted her, talks about becoming an advocate for mistreated women.
## 10 Staff Sgt. Logan J. Melgar, 34, a veteran of two deployments to Afghanistan, was found dead on June 4, and his superiors almost immediately suspected foul play.
## 11 Militants and smugglers operate in the impoverished African country, where the scale of American military involvement has surprised even high-ranking senators.
## 12 President Trump has pressed for aggressive financial deregulation, but the candidates for Federal Reserve chairman are unlikely to share those views.
## 13 Egypt dismissed a dozen top officials after an attack that killed a large number of police and elicited widespread criticism of the performance of Egypt’s security agencies.
## 14 But the conservative party, led by Prime Minister Bjarni Benediktsson, emerged somewhat weakened, losing five seats.
## 15 Here’s what you need to know to start your day.
## 16 Los Angeles and Houston are tied up at two games apiece in the series. Stay here for inning-by-inning updates and analysis.
## 17 Married F.B.I. agents who were fired for failing to disclose the use of fertility drugs are trying to reclaim their lives.
## 18 The Taliban have begun refining opium on their own, rather than exporting the raw ingredients, giving the militants even less reason to negotiate with the Afghan government.
## 19 As the social media giant grows in the developing world, its platform is being used to spread misinformation and incite violence.
## 20 A former priest who received a settlement from a victim compensation fund said that he was abused by the Rev. Robert V. Lott, forcing a reassessment of a man some called a saint.
## 21 The government said a proposal to create body representing Indigenous people would have failed if brought to a vote in a national referendum.
## 22 The high court ruled that Barnaby Joyce and other lawmakers had been ineligible to run for Parliament because they held dual citizenship.
## 23 A small town in New South Wales rewards visitors and locals with a charming Japanese cafe.
## 24 The staging is the star in Matthew Bourne’s adaptation of the 1948 movie, the most beloved ballet film ever, our critic writes.
## 25 The author of “Hamilton,” “Titan” and “Grant” confesses that he is a slow reader: “It would take me a year” to read one of his own books.
## 26 There are some key matchups in Week 8, but all eyes were on Houston as players responded to an offensive statement made by their owner.
## url
## 1 https://www.nytimes.com/2017/10/29/business/energy-environment/russia-venezula-oil-rosneft.html
## 2 https://www.nytimes.com/2017/10/29/us/politics/trump-clinton-mueller-russia.html
## 3 https://www.nytimes.com/2017/10/29/us/politics/roger-stone-twitter-suspended.html
## 4 https://www.nytimes.com/2017/10/29/us/politics/arizona-senate-race-flake-sinema-ward-bannon.html
## 5 https://www.nytimes.com/2017/10/28/business/401k-limit-tax-cuts.html
## 6 https://www.nytimes.com/2017/10/29/us/politics/democrats-tax-reform-middle-class.html
## 7 https://www.nytimes.com/2017/10/29/us/whitefish-cancel-puerto-rico.html
## 8 https://www.nytimes.com/2017/10/29/us/sacramento-sexual-harassment-california.html
## 9 https://www.nytimes.com/2017/10/28/us/rose-mcgowan-harvey-weinstein.html
## 10 https://www.nytimes.com/2017/10/29/us/politics/navy-seals-team-6-strangle-green-beret-mali.html
## 11 https://www.nytimes.com/2017/10/29/world/africa/niger-ambush-isis.html
## 12 https://www.nytimes.com/2017/10/29/business/federal-reserve-chairman-trump.html
## 13 https://www.nytimes.com/2017/10/29/world/middleeast/egypt-abdel-fattah-el-sisi.html
## 14 https://www.nytimes.com/2017/10/29/world/europe/iceland-election.html
## 15 https://www.nytimes.com/2017/10/29/briefing/russia-investigation-north-korea-catalonia.html
## 16 https://www.nytimes.com/2017/10/29/sports/world-series-dodgers-astros.html
## 17 https://www.nytimes.com/2017/10/28/us/politics/fbi-matt-litton-fertility.html
## 18 https://www.nytimes.com/2017/10/29/world/asia/opium-heroin-afghanistan-taliban.html
## 19 https://www.nytimes.com/2017/10/29/business/facebook-misinformation-abroad.html
## 20 https://www.nytimes.com/2017/10/29/nyregion/priest-sex-abuse-robert-lott.html
## 21 https://www.nytimes.com/2017/10/27/world/australia/indigenous-recognition-proposal.html
## 22 https://www.nytimes.com/2017/10/26/world/australia/citizenship-ruling.html
## 23 https://www.nytimes.com/2017/10/26/dining/federal-doma-cafe-review-japanese-food-nsw-australia.html
## 24 https://www.nytimes.com/2017/10/28/arts/dance/review-the-red-shoes-matthew-bourne.html
## 25 https://www.nytimes.com/2017/10/26/books/review/ron-chernow-by-the-book.html
## 26 https://www.nytimes.com/2017/10/29/sports/nfl-scores-texans-seahawks.html
## byline item_type updated_date
## 1 CLIFFORD KRAUSS Article 2017-10-29
## 2 JULIE HIRSCHFELD DAVIS Article 2017-10-29
## 3 JACEY FORTIN Article 2017-10-29
## 4 SHERYL GAY STOLBERG Article 2017-10-29
## 5 PATRICIA COHEN Article 2017-10-28
## 6 JIM TANKERSLEY Article 2017-10-29
## 7 FRANCES ROBLES and DEBORAH ACOSTA Article 2017-10-29
## 8 JESS BIDGOOD, MIRIAM JORDAN and ADAM NAGOURNEY Article 2017-10-29
## 9 SUSAN DOMINUS Article 2017-10-28
## 10 ERIC SCHMITT Article 2017-10-29
## 11 DIONNE SEARCEY and ERIC SCHMITT Article 2017-10-29
## 12 BINYAMIN APPELBAUM Article 2017-10-29
## 13 NOUR YOUSSEF Article 2017-10-29
## 14 RICHARD MARTYN-HEMPHILL Article 2017-10-29
## 15 CHARLES McDERMID Article 2017-10-29
## 16 BENJAMIN HOFFMAN and DAVID WALDSTEIN Article 2017-10-29
## 17 ADAM GOLDMAN Article 2017-10-29
## 18 MUJIB MASHAL Article 2017-10-29
## 19 KEVIN ROOSE Article 2017-10-29
## 20 SHARON OTTERMAN Article 2017-10-29
## 21 ADAM BAIDAWI Article 2017-10-27
## 22 ISABELLA KWAI Article 2017-10-27
## 23 BESHA RODELL Article 2017-10-26
## 24 BRIAN SEIBERT Article 2017-10-28
## 25 Article 2017-10-26
## 26 BENJAMIN HOFFMAN Article 2017-10-29
## updated_time created_date created_time published_date published_time
## 1 18:43:33 2017-10-29 18:43:33 2017-10-29 18:43:33
## 2 20:16:31 2017-10-29 12:53:25 2017-10-29 12:53:25
## 3 20:16:24 2017-10-29 18:30:14 2017-10-29 18:30:14
## 4 19:39:36 2017-10-29 09:12:16 2017-10-29 09:12:16
## 5 15:55:56 2017-10-28 13:00:58 2017-10-28 13:00:58
## 6 17:26:44 2017-10-29 13:23:28 2017-10-29 13:23:28
## 7 20:06:03 2017-10-29 13:07:16 2017-10-29 13:07:16
## 8 15:47:42 2017-10-29 15:47:43 2017-10-29 15:47:43
## 9 22:21:56 2017-10-28 14:56:23 2017-10-28 14:56:23
## 10 19:05:59 2017-10-29 14:58:14 2017-10-29 14:58:14
## 11 18:45:34 2017-10-29 18:14:45 2017-10-29 18:14:45
## 12 19:49:36 2017-10-29 19:49:36 2017-10-29 19:49:36
## 13 14:07:46 2017-10-29 14:07:46 2017-10-29 14:07:46
## 14 17:56:28 2017-10-29 09:22:34 2017-10-29 09:22:34
## 15 20:00:54 2017-10-29 14:59:00 2017-10-29 14:59:00
## 16 20:09:49 2017-10-29 18:23:53 2017-10-29 18:23:53
## 17 15:22:50 2017-10-28 11:32:14 2017-10-28 11:32:14
## 18 17:33:05 2017-10-29 13:45:05 2017-10-29 13:45:05
## 19 14:43:46 2017-10-29 14:43:46 2017-10-29 14:43:46
## 20 16:24:24 2017-10-29 16:24:24 2017-10-29 16:24:24
## 21 03:32:50 2017-10-27 03:32:51 2017-10-27 03:32:51
## 22 20:28:44 2017-10-26 23:46:43 2017-10-26 23:46:43
## 23 16:30:57 2017-10-26 13:35:12 2017-10-26 13:35:12
## 24 13:44:42 2017-10-28 13:44:42 2017-10-28 13:44:42
## 25 05:00:17 2017-10-26 05:00:17 2017-10-26 05:00:17
## 26 19:58:50 2017-10-29 12:19:40 2017-10-29 12:19:40
## material_type_facet
## 1 News
## 2 News
## 3 News
## 4 News
## 5 News
## 6 News
## 7 News
## 8 News
## 9 News
## 10 News
## 11 News
## 12 News
## 13 News
## 14 News
## 15 briefing
## 16 News
## 17 News
## 18 News
## 19 News
## 20 News
## 21 News
## 22 News
## 23 Review
## 24 Review
## 25 News
## 26 News