【发布时间】:2022-01-14 14:29:21
【问题描述】:
我有一个很大的列表,其中包括从语料库中提取的术语。
mylist <- list(c("flower"),
c("plant", "animal", "cats", "doggy"),
c("tree", "trees", "cat", "dog"))
提取的术语来自数据框(作为主要词、相似词和类别)
ref <- data.frame(id = c(1:5),
main = c("tree", "plant", "flower", "dog", "cat"),
similar = c("trees","plantlike", "flowery", "doggy", "cats"),
category = c("plant", "plant", "plant", "animal", "animal"))
我需要更改列表,以便使用类别而不是单词。并且可能会删除这样的重复项...
needed <- list("plant",
c("plant", "animal", "animal", "animal"),
c("plant", "plant", "animal", "animal"))
orbetter <- list("plant",
c("plant", "animal"),
c("plant", "animal"))
但我不知道如何为列表中的每个元素应用 sapply。感谢您的帮助。
【问题讨论】:
-
如何从
myList到needed?您是否正在针对ref执行查找? -
@emilliman5 是的 .. 我想将单词与参考数据框匹配。