我使用LDA与主题相关的数据帧terms
选择返回值:sapply对数据帧的列使用从另一个数据帧
Topic 1 Topic 2 Topic 3
foo1 bar1 cow1
foo2 bar2 cow2
foo3 bar3 cow3
在另一个数据帧items
,我有一个链接到一个主题的项目清单:
ItemID Topic
item1 1
item2 1
item3 2
item4 3
我想创建一个新的列items$terms
返回与该主题相关的条款:
ItemID Topic terms
item1 1 foo1 foo2 foo3
item2 1 foo1 foo2 foo3
item3 2 bar1 bar2 bar3
item4 3 cow1 cow2 cow3
我尝试这样做:
items$terms <- sapply(items$Topic,paste(terms[,x],collapse = " "))
# For each item, find the topic, and return the pasted terms from topicterms
但我得到的错误:
Error in [.data.frame(topicterms, , x) : object 'x' not found.
你能告诉我什么,我做错了?
什么是'topicterms'?可能你需要'sapply(items $ Topic,function(x)terms [paste(“Topic”,x)])' –