这是一个 1 列 2 行的 df:
x <- data.frame(a = c("crash", "parking"))
> x
a
1 crash
2 parking
我想添加一个新字段,其中包含新列 syns 中每个 x 的同义词:
library(dplyr)
library(qdap)
x <- x %>%
mutate(syns = synonyms(a, return.list = F, report.null = T))
给予
no match for the following: parking ======================== Error: wrong result size (75), expected 2 or 1
如果我运行:
> synonyms("crash", return.list = F)
我得到:
[1] "bang" "boom" "clang" "clash"
[5] "clatter" "clattering" "din" "racket"
[9] "smash" "smashing" "thunder" "break"
[13] "break up" "dash to pieces" "disintegrate" "fracture"
[17] "fragment" "shatter" "shiver" "splinter"
[21] "dash" "fall" "fall headlong" "give way"
[25] "hurtle" "lurch" "overbalance" "pitch"
[29] "plunge" "precipitate oneself" "sprawl" "topple"
[33] "bump (into)" "collide" "crash-land" "drive into"
[37] "have an accident" "hit" "hurtle into" "plough into"
[41] "run together" "wreck" "accident" "bump"
[45] "collision" "jar" "jolt" "pile-up"
[49] "prang" "smash-up" "thud" "thump"
[53] "bankruptcy" "collapse" "debacle" "depression"
[57] "downfall" "failure" "ruin" "be ruined"
[61] "fail" "fold" "fold up" "go belly up"
[65] "go broke" "go bust" "go to the wall" "go under"
[69] "emergency" "immediate" "intensive" "round-the-clock"
[73] "speeded-up" "telescoped" "urgent"
我可以看到 75 个返回的同义词,所以看起来我的代码正在尝试为每个同义词添加一行,而我希望将向量(在本例中包含 75 个单词)添加到 a 列崩溃旁边的单行中。
我该怎么做?
换句话说,我想将整个 chr 向量添加到 df 中的单个单元格
最佳答案
我们能做到
x %>%
rowwise() %>%
mutate(syns = list(synonyms(a, return.list = FALSE, report.null = TRUE)))
关于r - dplyr 与 qdap 发生变异 :synonmyms giving Error: wrong result size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44801522/