【问题标题】:Error in R using function rbind "names do not match previous names"R 中使用函数 rbind 时出错“名称与以前的名称不匹配”
【发布时间】:2021-02-12 19:49:03
【问题描述】:

我的 R 代码看起来是这样的(所有需要的库也都添加了):

  t_descriptive_g<- x %>% group_by(cntry) %>%
      summarise(mean_stflife=mean(stflife),
                stand.D_stflife = sd(stflife),
                mean_pray=mean(pray),
                stand.D_pray=sd(pray),
                N=n())
    t_descriptive_a<- x %>%
      summarise(mean_stflife=mean(stflife),
                stand.D_stflife = sd(stflife),
                mean_pray=mean(pray),
                stand.D_pray=sd(pray),
                N=n())
    t<- rbind(t_descriptive_g, cbind(group="Total", t_descriptive_a))
    kable(t)

通过运行这一行:

t<- rbind(t_descriptive_g, cbind(group="Total", t_descriptive_a))

我遇到了这样的错误:

Error in match.names(clabs, names(xi)) : 
  names do not match previous names
   

我的数据(前 19 行):

如何解决这个错误?

【问题讨论】:

    标签: r error-handling compiler-errors statistics


    【解决方案1】:

    cbind 中的列名应为 cntry,这将与 t_descriptive_g 中的列名匹配。

    data <- rbind(t_descriptive_g, cbind(cntry="Total", t_descriptive_a))
    

    【讨论】:

      猜你喜欢
      • 2012-08-14
      • 2023-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2017-03-18
      • 1970-01-01
      • 2011-01-31
      相关资源
      最近更新 更多