Sometimes you may want to export your data from R (.Rdata) to another format, such as TXT file (a tab-delimited text file) and CSV file (comma separated values file). However, most used statistical software are SAS, Stata and SPSS, so here we will show how you to export data to several formats.
In the code below,
dt is the name of data in R, and
mydata new data name.
(1) Exporting data to TXT (Tab Delimited Text File):
write.table(dt, "mydata.txt", sep=",")
(2) Exporting data to CSV:
(3) Exporting data to SPSS. Here is necessary to install foreing package:
require(foreign) write.foreign(dt, "mydata.txt", "mydata.sps", package="SPSS")
(4) Exporting data to Stata:
require(foreign) write.dta(dt, "mydata.dta")
(5) Export data to SAS:
library(foreign) write.foreign(dt, "mydata.txt", "mydata.sas", package="SAS")
Hope you find this short post useful.