在多列上的mutate中使用str_split时出错

时间:2019-12-23 13:21:08

标签: r stringr

我有小题词

persons <-
  tribble(
    ~Name,  ~Interviewer1,                    ~Interviewer2,            ~Interviewer3,
    "Bob",  "empathetic, adaptable",          "passionate, adaptable",  "courteous, diligent",
    "Jim",  "persistent, ambitious",          "passionate",             "ambitious, empathetic",
    "Mary", "empathetic, diligent, amiable",  "diligent, empathetic",  "empathetic"
  )

,并想用str_split拆分每一列,我希望分别有3个新的嵌套列表列。

我尝试过:

t <- persons %>%
  mutate(adj1 = str_split(~Interviewer1, ","), 
         adj2 = str_split(~Interviewer2, ","), 
         adj3 = str_split(~Interviewer3, ",")) 

但出现错误:

Error: Column `adj1` must be length 3 (the number of rows) or one, not 2

此错误是什么意思,我该如何解决? 谢谢

0 个答案:

没有答案