I have installed those packages: rvest stringr tidyr data.table plyr xml2 selectr tibble purr datapasta jsonlite
I have scraped UN FAO website for research and finally got this:
FAO_AreaName <-"MEX"
news_url <- paste0("http://www.fao.org/countryprofiles/common/allnews/en/?iso3=",FAO_AreaName,"&allnews=no&limit=2")
news<- fromJSON(news_url)
title <- news[3]
date <- news[6]
FAO_AreaName_1 <- news[5]
content_MEX <- news[5]
MEX <- cbind(FAO_AreaName, FAO_AreaName_1, date,title, content_MEX)
FAO_AreaName <-"FSM"
news_url <- paste0("http://www.fao.org/countryprofiles/common/allnews/en/?iso3=",FAO_AreaName,"&allnews=no&limit=2")
news<- fromJSON(news_url)
title <- news[3]
date <- news[6]
FAO_AreaName_1 <- news[5]
content_FSM <- news[5]
FSM <- cbind(FAO_AreaName, FAO_AreaName_1, date,title, content_FSM)
When I merge the two datasets I get this:
MERGE <- merge(MEX, FSM, by="FAO_AreaName", all=T)
str(MERGE)
'data.frame': 4 obs. of 7 variables:
$ FAO_AreaName : Factor w/ 2 levels "MEX","FSM": 1 1 2 2
$ date_format.x: chr "27/11/2017" "16/11/2017" NA NA
$ title.x : chr "México es sede de reunión regional sobre la iniciativa de Crecimiento Azul de la FAO " "Lograr el hambre cero pasa por reducir la pérdida y desperdicio de alimentos" NA NA
$ bodytext.x : chr " \r\n\r\nLa Comisión Nacional de Acuacultura y Pesca de México es anfitriona de la principal reunión sobre la actividad en Amér"| __truncated__ " \r\n\r\nSe realiza Foro sobre el desperdicio y pérdida de alimentos en México: retos y soluciones, organizado en el Senado de"| __truncated__ NA NA
$ date_format.y: chr NA NA "11/11/2017" "11/11/2017"
$ title.y : chr NA NA "Pacific leaders alarmed over climate change’s negative impact on food systems and food security" "Pacific leaders alarmed over climate change’s negative impact on food systems and food security"
$ bodytext.y : chr NA NA "11 November 2017, Rome – Climate change poses an alarming threat to food systems and food security in the Pacific islands, warn"| __truncated__ "11 November 2017, Rome – Climate change poses an alarming threat to food systems and food security in the Pacific islands, warn"| __truncated__
Of course, I do not want the variables duplication such as .x and .y