R语言结果输出到word |
您所在的位置:网站首页 › r语言回归结果表格 › R语言结果输出到word |
前言
关于R结果的导出,有不少的工具可以使用,包括:stargzer、R2word、Sweave R、Knitr、texreg等工具(来源于人大经济论坛讨论贴:如何将R运行结果自动保存?)此处仅介绍使用stargazer导出结果到word.使用的数据集为R自带的attitude数据集。 查看数据集 head(attitude) #查看前5行 str(attitude) #查看数据结构可以看到,该数据集包含8个变量,30条数据。 描述性统计 library('stargazer') #在工作空间展示 stargazer(attitude, title = "Tab了e 1. descriptive statistic",type = "text",no.space=TRUE,summary.stat=c('median','mean','sd','min','max')) #导出到相应路径,结果为doc的表格 stargazer(attitude, title = "Table 1. descriptive statistic",type ="html", out='C:/Users/xxx/Desktop/descriptive statistic')注:1)stargazer的summary.stat参数可以选择要展示的统计量,统计量的简写可见stargazer参数解释文件P23; 2)summary参数=FLASE,结果为查看整个数据集或数据集的子集,默认为TRUE; 3)rownames设置为FALSE来去掉行号; 4)其他见文件stargazer参数解释文件。 相关性分析 cor_matr=cor(attitude) #cor_matr=cor(df1,method = 'spearman') #在工作空间展示 stargazer(cor_matr, title = "Table 2. variable correlations",type = "text") #导出到相应路径,结果为doc的表格 stargazer(cor_matr, title = "Table2. variable correlations",type ="html", out='C:/Users/xxx/Desktop/correlation.doc') #计算相关系数的显著性 library('psych') corr.test(attitude, use = "complete",method = "pearson", adjust = "none") #可视化相关系数矩阵 library('corrplot') corrplot(corr = cor_matr,order = "AOE",type="upper",tl.pos = "d") corrplot(corr = cor_matr,add=TRUE, type="lower", method="number",order="AOE",diag=FALSE,tl.pos="n", cl.pos="n")
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |