Skip to content

Instantly share code, notes, and snippets.

@bfoste01
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfoste01/c4633c367cc8aa016e2b to your computer and use it in GitHub Desktop.
Save bfoste01/c4633c367cc8aa016e2b to your computer and use it in GitHub Desktop.
Insert Greek Symbols as Column Names in xtable outputs
#create artifical data to emulate SEM model fit statistics
chiSq <- 1600
df <- 780
p <- 0.95
CFI <- 0.95
TLI <- 0.95
RMSEA <- 0.04
LOWRMSEA <- 0.03
HIGHRMSEA <- 0.04
#append vectors above into a data frame to represent a data frame that might be produced for fit statisitcs from an SEM package
fit.stat <- data.frame(chiSq, df, p, CFI, TLI, RMSEA, LOWRMSEA, HIGHRMSEA)
#make HIGHRMSEA and LOWRMSEA appear as upper and lower bounds in same column as RMSEA
fit.stat <- data.frame(chiSq, df, p, CFI, TLI,
RMSEA = paste0(RMSEA , " (",LOWRMSEA," - ", HIGHRMSEA,")"))
#create a sanitize function to overide xtable defaults
formatcolheads<-function(x) {
sanitize<-get("sanitize", parent.frame())
x<-sanitize(x) #replace special features from xtable output
x<-gsub("chiSq","$x^2$",x) #latex mathematical replacement for chisq
x<-gsub("df","{\\\\it df}",x) #italicize df
x<-gsub("p","{\\\\it p}",x) #italicize p
x
}
#print xtable with function applied
library(xtable)
print(xtable(fit.stat, caption = "Model Fit Information for CFA"),
caption.placement = "top", sanitize.colnames.function = formatcolheads,
include.rownames = FALSE, type = "latex")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment