R語言—統計結果輸出至本地文件方法總結


1.sink()
在代碼開始前加一行:sink(“output.txt”),就會自動把結果全部輸出到工作文件夾下的output.txt文本文檔。這時在R控制台的輸出窗口中是看不到輸出結果的。代碼結束時用sink()切換回來。 

示例:

sink("a.txt") 
x<-rnorm(100,0,1) 
mean(x) 
sink() 

注:此處輸出為mean(x)。

2.stargazer()

library(stargazer)

#導入數據
mydata <- read.csv("intro_auto.csv")
attach(mydata)
Y <- cbind(mpg)
X1 <- cbind(weight)
X2 <- cbind(weight,price,foreign)

#生成描述統計表格
stargazer(mydata, type = "text")

#簡單的OLS回歸,獲得估計結果fit1和fit2
fit1 <- lm(Y~weight) 
fit2 <- lm(Y~weight+price+foreign)

#生成估計結果表格
stargazer(fit1, fit2, title = "results", align = F, type = "text", no.space = TRUE, out = "fit.html")
#需要注意的是,此命令中,在consol中生成的表格是text格式的,而導出的表格是html格式的(stargazer不能直接生成word文件),再用word打開fit.html文件就可以

3.xlsReadWrite包中的write.xls函數
尚未使用過。

4.R2wd包
---------------------
作者:Imliao
來源:CSDN
原文:https://blog.csdn.net/imliao/article/details/79367602


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM