r语言 - dplyr QDAP突变:同步给出错误:错误结果大小



这是一个1列DF,带2行:

x <- data.frame(a = c("crash", "parking"))
> x
        a
1   crash
2 parking

我想在新的列中添加一个新字段,每个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个返回的symonns,因此看来我的代码正在尝试为每个sumtomn添加一行,而我希望向量(在这种情况下使用75个单词(,将其添加到一排中,并在A carress a carress A. <<<<<<<<<。/p>

我该怎么做?

以换句话说,我想在DF

中添加整个CHR矢量

我们可以做

x %>%
  rowwise() %>% 
  mutate(syns = list(synonyms(a, return.list = FALSE, report.null = TRUE)))

最新更新