【问题标题】:How to combine tables with different numbers of columns in R?如何在R中组合具有不同列数的表?
【发布时间】:2020-02-25 13:06:22
【问题描述】:

我知道这一定是一个简单的解决方法,但我已经坚持了很长时间。我有三张桌子,两张三列,一张两列。我想将它们结合起来,以显示对于每个统计测试,特定模型有多少次是最佳模型。以下是我目前拥有的表格。将它们结合起来的最佳方法是什么,所以我将 R_Squared、AIC 和 BIC 作为列标题,将 Quadratic、Polynomial 和 Linear 作为结果的行名(以及 R Squared 列下的 Linear 为零)?非常感谢你的帮助!

【问题讨论】:

  • 请不要发布您的数据图像。使用 dput()....

标签: r model data-manipulation data-management


【解决方案1】:

不是最优雅的解决方案,但确实创建了所需的表。

library(dplyr)

# Data
R_Squared <- data.frame(Polynomial = c(283), Quadratic = c(2))
AIC <- data.frame(Polynomial = c(201), Quadratic = c(60), Linear = c(24))
BIC <- data.frame(Polynomial = c(196), Quadratic = c(62), Linear = c(27))

df <- bind_rows(AIC, BIC, R_Squared)
# add row names
row.names(df) <- c('AIC','BIK','R_Squared')
# returns the transpose of df
df <- t(df)

输出:

           AIC BIK R_Squared
Polynomial 201 196       283
Quadratic   60  62         2
Linear      24  27        NA

【讨论】:

    猜你喜欢
    • 2012-02-03
    • 2018-03-11
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多