在R data.table中匹配文本名称

问题描述:

我想将不同的data.tables与艺术家数据合并。但是,艺术家的名字在我的一些数据集中以不同的方式拼写。我正在寻找一种简单方便的方式来匹配这些艺术家的名字,这样我就可以给每位艺术家一个ID,这样可以更容易地合并我的数据集。我对R还是比较新的,我想知道你能不能给我一些关于这个话题的指导。艺术家名字基本上是不同data.tables中的字符串。在R data.table中匹配文本名称

+1

重复的例子? – lmo

您可以依次使用?revaluelibrary(plyr)纠正名称,然后将它们合并

dt_age <- data.table(artist=c("Dali","Van Gogh"), 
       age=c(85,37)) 
dt_paintings <- data.table(artist=c("dali","van gogh"), 
        paintings=c("The peristence of Memory","The Starry Night")) 

merge(dt_age,dt_paintings,by="artist") # this is empty 

artist_correct <- c("dali"="Dali", 
         "van gogh"="Van Gogh" 
        ) 
dt_paintings$artist <- revalue(dt_paintings$artist,artist_correct) 

merge(dt_age,dt_paintings,by="artist") # this is correct after we correct the names