我正在使用 texreg 进行回归输出。我想在表格中对齐小数点。但是,所有数字都处于数学模式,在“$”字符之间。是否可以选择仅将重要星号括在“$”中,而将数字保留为常规文本?
1 回答
0
使用 stringr 修改 texreg 的输出。对于任何有兴趣的人:
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)
})
于 2021-09-22T17:10:11.477 回答