AN INTRODUCTION TO R
R> csvForbes2000 <- read.table("Forbes2000.csv",
header = TRUE, sep = ",", row.names = 1,
colClasses = c("character", "integer", "character",
"factor", "factor", "numeric", "numeric", "numeric",
and check if this object is identical with our previous Forbes 2000 list object R> all.equal(csvForbes2000, Forbes2000)
 "Component \"name\": 23 string mismatches"
The argument colClasses expects a character vector of length equal to the number of columns in the file. Such a vector can be supplied by the c function that combines the objects given in the parameter list into a vector
R> classes <- c("character",
An R interface to the open data base connectivity standard (ODBC) is available in package RODBC and its functionality can be used to assess Excel and Access files directly:
R> library("RODBC") R> cnct <- odbcConnectExcel("Forbes2000.xls") R> sqlQuery(cnct, "select * from \"Forbes2000\\$\"")
The function odbcConnectExcel opens a connection to the specified Excel or Access file which can be used to send SQL queries to the data base engine and retrieve the results of the query.
Files in SPSS format are read in a way similar to reading comma separated files, using the function read.spss from package foreign (which comes with the base distribution).
Exporting data from R is now rather straightforward. A comma separated file readable by Excel can be constructed from a data.frame object via
R > w r i t e . t a b l e ( F o r b e s 2 0 0 0 , f i l e = " F o r b e s 2 0 0 0 . c s v " , s e p = " , " ,
col.names = NA)
The function write.csv is one alternative and the functionality implemented in the RODBC package can be used to write data directly into Excel spread- sheets as well.
Alternatively, when data should be saved for later processing in R only, R objects of arbitrary kind can be stored into an external binary file via