Is there a package in R that produces tables like this one:
Basically, given a dataset of factors and variables, produces a nicely-formatted table with pairwise t-tests and letters indicating significance of differences?
Dummy data:
var = c(rnorm(100,mean=1,sd=2),rnorm(30,mean=-1,sd=2),rnorm(50,mean=0,sd=4))
factor = as.factor(c(rep(1,100),rep(2,30),rep(3,50))
How would I take that dummy data and turn it into (one column of) the example table?
Disclaimer
Not an exact answer but it could be good start!!! Use tables package.
library(Hmisc)
library(tables)
stderr <- function(x) sd(x)/sqrt(length(x))
latex(
object = tabular((Species+1) ~ All(iris)* PlusMinus(mean, stderr, digits=1), data=iris)
, title = "Test"
, file=""
, size = "small"
, cdot = 3
, here = TRUE
, booktabs=TRUE
, center="centering"
)
Output

You can obtain letters using multcompView package.
library(multcompView)
Sepal.Length.fm <- aov(Sepal.Length~Species, data=iris)
Sepal.Length.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Sepal.Length.fm)$"Species"))$"Letters")
Sepal.Width.fm <- aov(Sepal.Width~Species, data=iris)
Sepal.Width.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Sepal.Width.fm)$"Species"))$"Letters")
Petal.Length.fm <- aov(Petal.Length~Species, data=iris)
Petal.Length.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Petal.Length.fm)$"Species"))$"Letters")
Petal.Width.fm <- aov(Petal.Width~Species, data=iris)
Petal.Width.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Petal.Width.fm)$"Species"))$"Letters")
Letters <- cbind(Sepal.Length.Letters, Sepal.Width.Letters, Petal.Length.Letters, Petal.Width.Letters)
Letters Letters Letters Letters
versicolor a a a a
virginica b b b b
setosa c c c c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With