-1

I know it must be a simple fix but I've been stuck on this for ages. I've got three tables, two with three columns, one with two columns. I want to combine them to show, for each statistical test, how many times a particular model was the best one. Below are the tables I have at the moment. What's the best way to combine them so I have R_Squared, AIC and BIC as the column headers and Quadratic, Polynomial and Linear as the row names with the results (and a zero for Linear under the R Squared column)? Thank you so much for your help!

Here are the tables I have at the moment

botinky
  • 9
  • 2
  • please do NOT post images of your data.. use `dput()`.... possible solution: `data.table::rbindlist()` with the `use.names` and `fill`-arguments. – Wimpel Feb 25 '20 at 13:12

1 Answers1

1

Not the most elegant solution but does create the desired table.

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)

Output:

           AIC BIK R_Squared
Polynomial 201 196       283
Quadratic   60  62         2
Linear      24  27        NA
camnesia
  • 2,143
  • 20
  • 26