1

I wish to create a number of tables with numerical elements of very different scales. For example, tables with the variance of various variables down the diagonal, and the correlations off the diagonal. The larger numbers make the tables too big, and are harder to read.

Is there a good way using stargazer (or some other, similar package) to scale down the elements that are much larger, and indicate this with a foot note, or automatically use exponential notation?

For example, the following r code creates a matrix where the diagonal elements are much larger than the other elements.

x <- matrix(rnorm(25,0,1),5,5)
diag(x) <- rnorm(5,10000000,10)
stargazer(x,summary=F,digits=2)

Any help much appreciated.

4

1 回答 1

0

也许您可以对此进行一些调整:

ifelse(x < 100, sprintf("%0.2f", x), sprintf("%0.5e", x))
#    [,1]          [,2]          [,3]          [,4]          [,5]         
#[1,] "9.99999e+06" "-0.79"       "-0.56"       "0.91"        "-2.57"      
#[2,] "-0.13"       "9.99999e+06" "-1.83"       "-0.34"       "1.73"       
#[3,] "-0.48"       "0.38"        "1.00000e+07" "1.40"        "-0.32"      
#[4,] "-0.05"       "-0.62"       "0.91"        "1.00000e+07" "1.15"       
#[5,] "-0.09"       "-0.33"       "-0.16"       "0.35"        "9.99999e+06"

或者,不带引号:

noquote(ifelse(x < 100, sprintf("%0.2f", x), sprintf("%0.5e", x)))
#     [,1]        [,2]        [,3]        [,4]        [,5]       
#[1,] 9.99999e+06 -0.79       -0.56       0.91        -2.57      
#[2,] -0.13       9.99999e+06 -1.83       -0.34       1.73       
#[3,] -0.48       0.38        1.00000e+07 1.40        -0.32      
#[4,] -0.05       -0.62       0.91        1.00000e+07 1.15       
#[5,] -0.09       -0.33       -0.16       0.35        9.99999e+06

您实际上是在转换为以您想要的方式打印的文本。有关输出选项的更多信息,请参阅?sprintf

于 2015-06-05T06:01:41.930 回答