write.table {base} | R Documentation |
Data Output
Description
write.table
prints its required argument x
(after
converting it to a data frame if it is not one already) to
file
. The entries in each line (row) are separated by the
value of sep
.
Usage
write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
eol = "\n", na = "NA", dec = ".", row.names = TRUE,
col.names = TRUE, qmethod = c("escape", "double"))
Arguments
x |
the object to be written, typically a data frame. If not, it
is attempted to coerce |
file |
either a character string naming a file or a connection.
|
append |
logical. If |
quote |
a logical or a numeric vector. If |
sep |
the field separator string. Values within each row of
|
eol |
the character(s) to print at the end of each line (row). |
na |
the string to use for missing values in the data. |
dec |
the string to use for decimal points. |
row.names |
either a logical value indicating whether the row
names of |
col.names |
either a logical value indicating whether the column
names of |
qmethod |
a character string specifying how to deal with embedded
double quote characters when quoting strings. Must be one of
|
Details
Normally there is no column name for a column of row names. If
col.names=NA
a blank column name is added. This can be used to
write CSV files for input to spreadsheets.
See Also
The ‘R Data Import/Export’ manual.
read.table
, write
.
Examples
## Not run:
## To write a CSV file for input to Excel one might use
write.table(x, file = "foo.csv", sep = ",", col.names = NA)
## and to read this file back into R one needs
read.table("file.csv", header = TRUE, sep = ",", row.names=1)
## End(Not run)