Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Export

Export a data frame to disk in one of many formats


Description

Uses the export function in the rio package to export a file to disk. This function adds an argument for converting row.names to a column in the resulting file.

Usage

Export(x, file, format, ..., keep.row.names)

Arguments

x

A data frame or matrix to be written to a file.

file

A character string naming a file. If the file name has an extension, such as .xlsx, the extention is used to infer the type of file to be exported. See export for the file types supported.

format

see export.

...

Additional arguments; see export.

keep.row.names

If set to TRUE, then the data frame's row.names are appended to the left of the data frame with the name "id". If set to quoted character string, the row.names are added using the character string as its name. If set to FALSE row.names are lost.

Details

This is a convenience function in the car package for exporting (writing) a data frame to a file in a wide variety of formats including csv, Microsoft Excel. It optionally allows converting the row.names for the data frame to a column before writing. It then calls export in the rio package. That function in turn uses many other packages and functions for writing the function to a file.

Value

The name of the output file as a character string (invisibly).

Author(s)

Sanford Weisberg sandy@umn.edu

References

Chung-hong Chan, Geoffrey CH Chan, Thomas J. Leeper, and Jason Becker (2017). rio: A Swiss-army knife for data file I/O. R package version 0.5.0.

See Also

Examples

Export(Duncan, "Duncan.csv", keep.row.names="occupation")
Duncan2 <- Import("Duncan.csv") # Automatically restores row.names
identical(Duncan, Duncan2)
# cleanup
unlink("Duncan.csv")

car

Companion to Applied Regression

v3.0-10
GPL (>= 2)
Authors
John Fox [aut, cre], Sanford Weisberg [aut], Brad Price [aut], Daniel Adler [ctb], Douglas Bates [ctb], Gabriel Baud-Bovy [ctb], Ben Bolker [ctb], Steve Ellison [ctb], David Firth [ctb], Michael Friendly [ctb], Gregor Gorjanc [ctb], Spencer Graves [ctb], Richard Heiberger [ctb], Pavel Krivitsky [ctb], Rafael Laboissiere [ctb], Martin Maechler [ctb], Georges Monette [ctb], Duncan Murdoch [ctb], Henric Nilsson [ctb], Derek Ogle [ctb], Brian Ripley [ctb], William Venables [ctb], Steve Walker [ctb], David Winsemius [ctb], Achim Zeileis [ctb], R-Core [ctb]
Initial release
2020-09-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.