Importing Raw data files into R

You may load files created with the R edit() function or exported from other statistical or spreadsheet programs. Sometimes it is necessary to edit the files to make sure that the data format, variable names, and missing value codes are compatible with R. It is usually easiest to move the file to the Desktop. If you are working on your own personal machine, you can store files in the R folder.

Note: on the Macintosh systems in ETC211 you may need to change the working directory before using edit(). Pull down the tools menu, select "change working directory", and select "Desktop". Don't forget to hit the "continue" button to apply the change.

Example: Suppose you have a file with several variables, stored in plain text format in columns with spaces between the values, and names of the variables at the top of each column. Load the data into R using the read.table() function:

   Junk <- read.table("junk.dat",header=T)
Be sure you look at the resulting data.frame to check for problems.

Exporting Raw data files from R

The write.table() function reverses this process, and creates a file in plain text, tabular format. If "Junk" is the name of a dataset, then
     write.table(Junk, "junk.dat")
will create a file containing the data named "junk.dat". Again, on the ETC Mac's you will need to change the working directory to the Desktop first.