【发布时间】:2018-05-11 03:31:37
【问题描述】:
我已经安装了这些软件包: 投资 弦乐 蒂迪尔 数据表 plyr xml2 选择器 小标题 咕噜咕噜 数据面食 jsonlite
我在联合国粮农组织网站上搜索了一下,终于得到了这个:
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)
当我合并两个数据集时,我得到了这个:
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__
当然,我不希望 .x 和 .y 等变量重复
【问题讨论】:
-
制作你想要的变量子集?
-
我不想进行子集化。例如,我希望“title.x”和“title.y”只是“title”。
-
与
rbind你有解决方案。详情见我的帖子。 -
非常感谢。它工作得很好。其实我没想到
rbind。
标签: r variables merge duplicates dataset