SoFunction
Updated on 2025-03-01

Examples of several methods for outputting R language statistics results to local files

()

Add a line before the code starts: sink(""), and the results will be automatically output to the text document in the working folder. At this time, the output result cannot be seen in the output window of the R console. When the code ends, use sink() to switch back.

Example:

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

Note: The output here is mean(x).

()

library(stargazer)

#Import datamydata &lt;- ("intro_auto.csv")
attach(mydata)
Y &lt;- cbind(mpg)
X1 &lt;- cbind(weight)
X2 &lt;- cbind(weight,price,foreign)

#Generate a descriptive statistics tablestargazer(mydata, type = "text")

#Simple OLS regression to obtain estimated results fit1 and fit2fit1 &lt;- lm(Y~weight) 
fit2 &lt;- lm(Y~weight+price+foreign)

#Generate an estimate result tablestargazer(fit1, fit2, title = "results", align = F, type = "text",  = TRUE, out = "")
#It should be noted that,In this command,existconsolThe generated table istextFormat,The exported table ishtmlFormat(stargazerCan't generate directlyworddocument),Use againword打开document就可以

Functions in packages

Not used yet.

4.R2wd package

Summarize

This is the article about outputting R statistics results to local files. For more relevant R language results, please search for my previous articles or continue browsing the related articles below. I hope you will support me in the future!