This section deals with the basic structures R uses to store data and how to assemble them, as well as how to get data into and out of R.


Data structures in R

All R objects have a type or mode, as well as a class, which can be determined with typeof, mode & class.


Data input/output in R

For a basic introduction, see getting started. See also the R Data Import/Export manual.

R recognises a variety of formats for reading in data. For tabular data, the basic command read.table offers a powerful range of options, which is also used by the shortform commands read.csv and read.delim, for reading in comma-separated variable (e.g. output from a spreadsheet) and tab-delimited format data, respectively. Similarly, the command write.table is used to output tabular format data.

For fixed-width format data, use read.fwf. A more powerful method is to read in data directly into a vector or list, using scan. The following are useful functions for reading and writing a variety of data types. See their respective help pages for details.


Other packages for R data input / output

There are a number of separate packages for reading and writing data in different formats. The following are some common examples; see the R Data Import/Export manual for more information.


Entering & editing data within R


Saving & loading R objects


For further information, you can find out more about how to access, manipulate, summarise, plot and analyse data using R.

Also, why not check out some of the graphs and plots shown in the R gallery, with the accompanying R source code used to create them.


Quick links


Jump to


Copyright © 2010-2013 Alastair Sanderson