write.data | R Documentation |
This function writes a (1) data file in CSV (.csv
), DAT (.dat
),
or TXT (.txt
) format using the fwrite
function from the data.table
package, (2) SPSS file (.sav
) using the write.sav
function, (3)
Excel file (.xlsx
) using the write.xlsx
function, or a (4) Stata
DTA file (.dta
) using the write.dta
function in the misty
package. Note that the function write.data
uses ","
for decimal
point and a semicolon ";"
for the separator, while the function
write.data1
uses "."
for decimal point and a comma ","
for the separator when writing a CSV file.
write.data(x, file = "Data.csv", sep = ";", dec = ",", na = "",
row.names = FALSE, col.names = TRUE, check = TRUE, ...)
write.data1(x, file = "Data.csv", sep = ",", dec = ".", na = "",
row.names = FALSE, col.names = TRUE, check = TRUE, ...)
x |
a matrix or data frame to be written. |
file |
a character string indicating the name of the data file
with the file extension |
sep |
a character string indicating the field separator, i.e.,
string for the delimiter. By default, the |
dec |
a character string indicating the decimal separator, i.e.,
string for decimal points. By default, the |
na |
a character string to use for missing values in the data.
By default, a blank string |
row.names |
logical: if |
col.names |
logical: if |
check |
logical: if |
... |
additional arguments to pass to the |
The function write.data
writes CSV files based on the Excel convention for CSV files in some Western
European locales by default, i.e., ";"
as delimiter and ","
for
decimal points. Depending on the language setting of the operating system of
the computer, the arguments sep
and dec
need to be specified to
","
and "."
(see Example 1b). Alternatively, the function
write.data1
that uses ","
as delimiter and "."
for
decimal points by default can be used (see Example 1c).
Takuya Yanagida
Barrett, T., Dowle, M., Srinivasan, A., Gorecki, J., Chirico, M., Hocking, T., & Schwendinger, B. (2024). data.table: Extension of 'data.frame'. R package version 1.16.0. https://CRAN.R-project.org/package=data.table
Jeroen O. (2021). writexl: Export Data Frames to Excel 'xlsx' Format. R package version 1.4.0. https://CRAN.R-project.org/package=writexl
Wickham H, Miller E, Smith D (2023). haven: Import and Export 'SPSS', 'Stata' and 'SAS' Files. R package version 2.5.3. https://CRAN.R-project.org/package=haven
read.data
, read.sav
,
write.sav
, write.xlsx
,
read.dta
, write.dta
, read.mplus
,
write.mplus
## Not run:
# Example 1a: Write CSV data file, European format
write.data(mtcars, "European_CSV_Data.csv")
# Example 1b: Write CSV data file, American format
write.data(mtcars, "American_CSV_Data.csv", sep = ",", dec = ".")
# Example 1c: Write CSV data file, American format
write.data1(mtcars)
# Example 2: Write SPSS data file
write.data(mtcars, "SPSS_Data.sav")
# Example 3: Write Excel data file
write.data(mtcars, "Excel_Data.xlsx")
# Example 4: Write Stata data file
write.data(mtcars, "Stata_Data.dta")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.