Last active
August 29, 2015 14:03
-
-
Save bfoste01/c4633c367cc8aa016e2b to your computer and use it in GitHub Desktop.
Insert Greek Symbols as Column Names in xtable outputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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