我有一个包含不同股票回报的数据集,我想在stargazer表中显示这些回报。问题是数据帧中的最后一行在3列中的2列中包含NA。此外,当我用stargazer输出时,它显示平均值、最大值、最小值等。我只想要数据帧中的实际返回值。
示例代码:
#Creating dataframe
X <- data.frame("Group" = c("Value", "Growth", "HML"), "Excess of riskfree" = c(0.1, 0.2,NA),
"Excess of Market" = c(0.2,0.4,NA), "Nominal" = c(0.5, 0.6, 0.01))
#Displaying my dataframe
> X
Group Excess.of.riskfree Excess.of.Market Nominal
1 Value 0.1 0.2 0.50
2 Growth 0.2 0.4 0.60
3 HML NA NA 0.01
#Setting up stargazer table
stargazer(X, title="Table 1: Returns", align=T, digits=4, out="Table1_Ret.txt", no.space=T, flip=T)
#This gives the following table
Table 1: Returns
=====================================================
Statistic Excess.of.riskfree Excess.of.Market Nominal
-----------------------------------------------------
N 2 2 3
Mean 0.1500 0.3000 0.3700
St. Dev. 0.0707 0.1414 0.3158
Min 0.1000 0.2000 0.0100
Pctl(25) 0.1250 0.2500 0.2550
Pctl(75) 0.1750 0.3500 0.5500
Max 0.2000 0.4000 0.6000
-----------------------------------------------------
基本上,我希望stargazer表在某种程度上等于我的数据帧在R中的显示(分组为行,变量为列名(。只显示返回值,而不是默认布局的统计方法。
不一定非得是观星包里的桌子,如果有其他(更简单(的解决方案,我也很乐意收到!
您所要做的就是添加summary=FALSE选项并将flip选项设置为F:
stargazer(X, summary=F, title="Table 1: Returns", align=T, digits=4, out="Table1_Ret.txt", no.space=T, flip=F)
#Gives you this:
Table 1: Returns
====================================================
Group Excess.of.riskfree Excess.of.Market Nominal
----------------------------------------------------
1 Value 0.1000 0.2000 0.5000
2 Growth 0.2000 0.4000 0.6000
3 HML 0.0100
----------------------------------------------------
此外:观星者只是将NA细胞留空。如果你想把它放在表中,只需把它添加为String:
X <- data.frame("Group" = c("Value", "Growth", "HML"), "Excess of riskfree" = c(0.1, 0.2,"NA"),
"Excess of Market" = c(0.2,0.4,"NA"), "Nominal" = c(0.5, 0.6, 0.01))
#Then you get this:
Table 1: Returns
====================================================
Group Excess.of.riskfree Excess.of.Market Nominal
----------------------------------------------------
1 Value 0.1 0.2 0.5000
2 Growth 0.2 0.4 0.6000
3 HML NA NA 0.0100
----------------------------------------------------
有关更多布局选项,请参阅stargazer文档1。