I am using texreg for regression output. I would like to align on decimals in the table. However, all numbers are in math mode, between '$' characters. Is there an option to only enclose the significance stars in '$', leaving the numbers as regular text?
Asked
Active
Viewed 99 times
0
-
Can you show your table? Maybe an `S` column from siunitx could help? – samcarter_is_at_topanswers.xyz Sep 22 '21 at 14:56
-
Thanks for the suggestion. I am using LyX, and it looks like I cannot easily override the provided column options. – John Janmaat Sep 22 '21 at 17:06
-
There are `texreg` arguments for decimal point alignment, such as `dcolumn` and `siunitx`. Have you considered those? – Philip Leifeld Sep 24 '21 at 11:06
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 30 '21 at 04:00
1 Answers
0
Used stringr to modify the output of texreg. For anyone interested:
tex <- texreg(list(model1,model2,model3,model4),
digits = 3,
stars=c(0.1,0.05,0.01,0.001),
symbol='+')
#
# convert numbers to text, grabbing stars and keeping between math symbols.
library(stringr)
newTex <- str_replace_all(tex,"\\$\\(?-?\\d+(,\\d+)*(\\.\\d+(e\\d+)?)?\\)?\\^?\\{?(\\*+)?\\+?\\}?\\$",
function(x) {
if(str_detect(x,"\\^")) {
ret <- sub("^","$^",sub("$","",x,fixed=T),fixed=T)
} else {
ret <- gsub("$","",x,fixed=T)
}
return(ret)
})

John Janmaat
- 1
- 1