%in%导致null输出

时间:2017-03-13 12:30:50

标签: r merge

数据集1

location
Bhilai, C.G
Delhi
Dadar, Mumbai
Bangalore, India

数据集2

location  state
Bhilai    C.G
Delhi     Delhi
Dadar     Maharastra
Bangalore Karnataka

我想要一个像这样的输出

输出

location                 state
Bhilai, C.G              C.G
Delhi                    Delhi
Dadar, Mumbai            Maharashtra
Bangalore, India         Karnatak

使用过的代码:

>    loc$key = 1
>    location2$key = 1
>    newdataset <- merge(loc, location2, by="key")
>    newdataset <- newdataset[newdataset$location.y %in% newdataset$location.x,
         c("location.x", "state")]

输出:

[1] location.x state.y   
<0 rows> (or 0-length row.names)

0 个答案:

没有答案