我使用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)])' –