我正在尝试在文本正文中构建一个彼此接近的单词字典。
假设我有这个:
> words
[1] "thanks" "fish" "long"
然后我希望能够做到这样的事情(在apply
构造中):
dictionary$words[i] <- words[-i]
并以此结束:
> dictionary
$thanks
[1] "fish" "long"
$fish
[1] "thanks" "long"
$long
[1] "thanks" "fish"
我尝试了assign
,但我无法做到正确,我甚至不确定这是否可行。
答案 0 :(得分:2)
尝试:
setNames(lapply(words, function(u) words[words!=u]), words)
#$thanks
#[1] "fish" "long"
#$fish
#[1] "thanks" "long"
#$long
#[1] "thanks" "fish"