[英]Create a stratified table (pivot table) of summary statistics from a survey object
[英]Create and Export a Summary Statistics Table
我有一個包含加密、標准普爾 500 ETF、CRIX、美聯儲儲備、商品等信息的數據集。我正在嘗試創建一個匯總統計表,發現包“stargazer”是最好的研究出版物。 我不希望數據集中的所有變量都在表中,所以我嘗試了以下代碼:
stargazer(df[c("BNBClose", "BTCClose", "ADAClose", "LINKClose", "DODGEClose", "EOSClose", "ETHClose", "MIOTAClose", "LTCClose", "XMRClose", "XEMClose", "XLMClose", "USDTClose", "TRXClose", "XRPClose", "FEDWALCL", "FEDM0Reserves", "FEDM0Total", "CETFClose", "CRIXClose", "SPYClose", "GLDClose", "OILClose")],type="text",title="Summary Statistics", out="table1.txt")
並發生以下錯誤:
Error in if (length(c(year, month, day, hour, min, sec)) == 6 && all(c(year, :
missing value where TRUE/FALSE needed
我在整個數據集中沒有缺失值。 我不知道還能做什么。 任何幫助將非常感激。 如果您有另一個包建議嘗試生成和導出(到乳膠)包含均值、標准差、最小值、最大值、偏度和峰度的描述性統計表也會有很大幫助。
可重現的示例數據集如下:
data_stuct <-
structure(
list(
Date = structure(
c(
17441,
17442,
17443,
17444,
17445,
17446,
17447,
17448,
17449,
17450
),
class = "Date"
),
BNBClose = c(
1.96466994285583,
1.82070004940032,
1.60148000717163,
1.67849004268646,
1.57991003990173,
1.58424997329711,
1.21722996234893,
1.4037799835205,
1.39336001873016,
1.43373000621795
),
BNBReturn = c(
0.286941022473697,
-0.0747675854046642,-0.135036469092375,
0.0266057079361807,
-0.058069140833992,
-0.0130882480387323,-0.227734156731425,
0.162348536759326,
-0.0263508788443867,
0.0245026259536907
),
BTCClose = c(
4409.31982421875,
4317.47998046875,
4229.35986328125,
4328.41015625,
4370.81005859375,
4426.89013671875,
4610.47998046875,
4772.02001953125,
4781.990234375,
4826.47998046875
),
BTCReturn = c(
0.00307332788380803,-0.0206375880182435,
-0.0208387453411515,
0.0232938703148199,
0.0107181238986895,
0.0131690154774654,
0.0408179529812949,
0.0341313938033363,
0.00121022180447976,
0.00777365568069113
),
ADAClose = c(
0.0259317997843027,
0.0208158008754253,
0.0219314992427825,
0.0214887000620365,
0.0185391008853912,
0.0209408998489379,
0.0204771999269723,
0.02211369946599,
0.0215313006192445,
0.0225195009261369
),
ADAReturn = c(
0.0538382925523828,
-0.191826507565934,
0.0511596482131408,
-0.0210738824748107,
-0.132019856680562,
0.137233310475833,
-0.0216059683246936,
0.0869727271720155,
-0.026266109908542,
0.0483939151162756
),
LINKClose = c(
0.356766998767852,
0.345535010099411,
0.397361010313034,
0.406538009643554,
0.475764989852905,
0.463656991720199,
0.397136986255645,
0.380589008331298,
0.407469004392623,
0.450462996959686
),
LINKReturn = c(
-0.184843753787707,
-0.059138850859273,
0.157859063823257,
0.0239478473239544,
0.170914967745977,
-0.0181875540911234,
-0.141299439924916,-0.0591264151564786,
0.0711621651773824,
0.0819438214938677
),
DODGEClose = c(
0.00108535995241254,
0.0011083900462836,
0.00102437997702509,
0.001001329976134,
0.00105603004340082,
0.00106609996873885,
0.00105591001920402,
0.000990716973319649,
0.00103567994665354,
0.00104612996801733
)
),
row.names = c(NA,-10L),
class = c("tbl_df",
"tbl", "data.frame")
)
我嘗試通過運行代碼對未聲明為時間序列的數據集進行匯總:
stargazer(WorkingVariables, type = "text", title = "Summary Statistics", out = "table1.txt")
控制台中的輸出具有我正在尋找的結構(或多或少,缺少觀察次數、偏度和峰度)但它是空的。 它顯示如下:
Summary Statistics
===================================================
Statistic N Mean St. Dev. Min Pctl(25) Pctl(75) Max
===================================================
底下什么都沒有,有人知道發生了什么嗎? 相同的樣本數據應該有效。
你有一個 tibble 和stargazer
不支持它。 如果您將其更改為數據框,則它可以工作。
library(stargazer)
data_stuct <- data.frame(data_stuct)
stargazer(data_stuct[c("BNBClose", "BTCClose", "ADAClose", "LINKClose",
"DODGEClose")],type="text",title="Summary Statistics", out="table1.txt")
#Summary Statistics
#========================================================================
#Statistic N Mean St. Dev. Min Pctl(25) Pctl(75) Max
#------------------------------------------------------------------------
#BNBClose 10 1.568 0.219 1.217 1.411 1.659 1.965
#BTCClose 10 4,507.324 220.613 4,229.360 4,339.010 4,731.635 4,826.480
#ADAClose 10 0.022 0.002 0.019 0.021 0.022 0.026
#LINKClose 10 0.408 0.043 0.346 0.385 0.440 0.476
#DODGEClose 10 0.001 0.00004 0.001 0.001 0.001 0.001
------------------------------------------------------------------------
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.