table2spreadsheet {export} | R Documentation |
Export statistical output to a table in spreadsheet compatible format (.xlsx or .csv)
Description
Export currently showing R stats object or stats object obj to a Microsoft Excel / LibreOffice Calc or comma-separated value file
Usage
table2spreadsheet(
x = NULL,
file = "Rtable",
type = c("XLS", "CSV", "CSV2"),
append = FALSE,
sheetName = "new sheet",
digits = 2,
digitspvals = 2,
trim.pval = 1e-16,
add.rownames = FALSE,
...
)
table2excel(...)
table2csv(...)
table2csv2(...)
Arguments
x |
given R stats object to export; if set to |
file |
name of output file. The .xlsx or .csv extension is added automatically. |
type |
desired output type - |
append |
logical value - if |
sheetName |
a string giving the name of the new sheet that is created (only for |
digits |
number of significant digits to show for all columns except for the column with p values. |
digitspvals |
number of significant digits to show for columns with p values. |
trim.pval |
a threshold below which the p-values are trimmed as
"< |
add.rownames |
logical specifying whether or not to add row names. |
... |
extra options are passed on to |
Details
Columns corresponding to degrees of freedom (with header "Df" or "df")
are always given as integers. Objects that can be exported with table2office
are
all those supported by xtable
and tidy
. The function will
first use xtable
to format the data. If the data class is not supported by
xtable
the function will then use tidy
.
The data classes suported by xtable
are:
-
anova
-
aov
-
aovlist
-
data.frame
-
glm
-
gmsar
-
lagImpact
-
lm
-
matrix
-
prcomp
-
sarlm
-
sarlm.pred
-
spautolm
-
sphet
-
splm
-
stsls
-
summary.aov
-
summary.aovlist
-
summary.glm
-
summary.gmsar
-
summary.lm
-
summary.prcomp
-
summary.sarlm
-
summary.spautolm
-
summary.sphet
-
summary.splm
-
summary.stsls
-
table
-
ts
-
zoo
The data classes suported by tidy
are:
-
aareg
-
acf
-
Arima
-
betareg
-
biglm
-
binDesign
-
binWidth
-
brmsfit
-
btergm
-
cch
-
character
-
cld
-
coeftest
-
confint.glht
-
cv.glmnet
-
default
-
density
-
dgCMatrix
-
dgTMatrix
-
dist
-
emmGrid
-
ergm
-
felm
-
fitdistr
-
ftable
-
gam
-
Gam
-
gamlss
-
geeglm
-
glht
-
glmnet
-
glmRob
-
gmm
-
htest
-
ivreg
-
kappa
-
kde
-
kmeans
-
Line
-
Lines
-
list
-
lme
-
lmodel2
-
lmRob
-
logical
-
lsmobj
-
manova
-
map
-
Mclust
-
merMod
-
mle2
-
muhaz
-
multinom
-
nlrq
-
nls
-
NULL
-
numeric
-
orcutt
-
pairwise.htest
-
plm
-
poLCA
-
Polygon
-
Polygons
-
power.htest
-
pyears
-
rcorr
-
ref.grid
-
ridgelm
-
rjags
-
roc
-
rowwise_df
-
rq
-
rqs
-
sparseMatrix
-
SpatialLinesDataFrame
-
SpatialPolygons
-
SpatialPolygonsDataFrame
-
spec
-
speedlm
-
stanfit
-
stanreg
-
summary.glht
-
summaryDefault
-
survdiff
-
survexp
-
survfit
-
survreg
-
tbl_df
-
TukeyHSD
Value
A data frame
Functions
-
table2excel()
: Export statistical output to a table in a Microsoft Office Excel/ LibreOffice Calc spreadsheet -
table2csv()
: Export statistical output to a table in a CSV format ("," for value separation and "." for decimal) -
table2csv2()
: Export statistical output to a table in a CSV format (";" for value separation and "," for decimal)
Author(s)
Tom Wenseleers, Christophe Vanderaa
See Also
table2tex
, table2html
, table2office
Examples
# Create a file name
filen <- tempfile(pattern = "table_aov") # or
# filen <- paste("YOUR_DIR/table_aov")
# Generate ANOVA output
fit=aov(yield ~ block + N * P + K, data = npk) # 'npk' dataset from base 'datasets'
x=summary(fit)
# Save ANOVA table as a CSV
### Option 1: pass output as object
table2csv(x=x,file=filen, digits = 1, digitspvals = 3)
### Option 2: get output from console
summary(fit)
table2csv(file=filen, digits = 2, digitspvals = 4)
# Save ANOVA table as an Excel
# Without formatting of the worksheet
x
table2excel(file=filen, sheetName="aov_noformatting",
digits = 1, digitspvals = 3)
# With formatting of the worksheet
table2excel(x=x,file=filen, sheetName="aov_formated",
append = TRUE, add.rownames=TRUE, fontName="Arial",
fontSize = 14, fontColour = rgb(0.15,0.3,0.75),
border=c("top", "bottom"), fgFill = rgb(0.9,0.9,0.9),
halign = "center", valign = "center", textDecoration="italic")