Learn R Programming

export (version 0.3.0)

table2spreadsheet: 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(...)

Value

A data frame

Arguments

x

given R stats object to export; if set to NULL the output of the previous R command will be exported.

file

name of output file. The .xlsx or .csv extension is added automatically.

type

desired output type - "XLS" for Excel and "CSV"/"CSV2" for CSV file. Note that type="CSV2" will generate a CSV file where the value separator is a semi-colon (";") and the decimal separator is a comma (",")

append

logical value - if TRUE and type="XLS" it will add a new woorksheet to the given file, where file can also be a given corporate. append=FALSE any existing file will be overwritten.

sheetName

a string giving the name of the new sheet that is created (only for type=="XLS"). It must be unique (case insensitive) from any existing sheet name in the file.

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 "< trim.pval".

add.rownames

logical specifying whether or not to add row names.

...

extra options are passed on to createStyle for the formatting of the woorksheet. This is only applicable for type=="XLS".

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

Tom Wenseleers, Christophe Vanderaa

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

See Also

table2tex, table2html, table2office

Examples

Run this code
# 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") 


Run the code above in your browser using DataLab