Learn R Programming

lessR (version 2.8)

Write: Write the Contents of Data Frame mydata to an External File

Description

Abbreviation: wrt, wrt.r

Writes the contents of the specified data frame, such as with the default mydata, to the current working directory as either the default csv data file or an R native data file of the specified data frame.

Usage

Write(ref, format=c("csv", "R"), data=mydata, ...)

wrt(...)

wrt.r(..., format="R")

Arguments

ref
Name of the output file as a character string, that is, with quotes. If not included in the name, the file type is automatically added to the name, either .csv or .rda, depending of the value of form
format
Format of file to be written with .csv as the default.
data
Data frame to be written as an object, that is, no quotes.
...
Other parameter values consistent with the usual write.table, such as row.names=FALSE to suppress writing the row names.

Details

Can specify the file name without the file type, which Write adds automatically, .csv for a comma separated values data file and .rda for a native R data file. The default file name is the name of the data frame to be written. The name of the file that is written, as well as the name of the working directory into which the file was written, are displayed at the console.

Write is designed to work in conjunction with the function Read from this package, which reads a csv, fixed width format, or native SPSS or R data files into the data frame mydata. Write relies upon the R functions write.csv and save.

See Also

Read, write.csv, save.

Examples

Run this code
# create data frame called mydata
n <- 12
X <- sample(c("Group1","Group2"), size=n, replace=TRUE)
Y <- rnorm(n=n, mean=50, sd=10)
mydata <- data.frame(X,Y)

# write the current contents of default data frame mydata to GoodData.csv
Write("GoodData")
# short name
# write the default data frame mydata to the R data file mydata.rda
wrt.r()

# access the R data frame warpbreaks
data(warpbreaks)
# write the file warpbreaks.rda
wrt.r(data=warpbreaks)

Run the code above in your browser using DataLab