read.xls {xlsReadWrite}R Documentation

Read Excelfiles

Description

Reads an Excelsheet and returns a data.frame or a matrix. Currently supported is the .xls (BIFF8) file format.

Usage

read.xls( file, 
          colNames = TRUE, 
          sheet = 1, 
          type = "data.frame",
          from = 1, 
          rowNames = NA, colClasses = NA, checkNames = TRUE, 
          dateTimeAs = "numeric", 
          stringsAsFactors = default.stringsAsFactors() )

Arguments

file the name of a file. If it does not contain an absolute path, the file name is relative to the current working directory.
colNames a character vector or a logical. TRUE takes a title row from the spreadsheet. The default is "V" followed by the column number.
sheet to read from. A case sensitive character string or a number.
type the type of the returned value. Either data.frame or - for matrices - double, integer, logical or character.
from the starting row to read from.
rowNames a character vector with the actual row names or a logical. TRUE uses the first Excel column for the rownames, with FALSE no rownames will be taken from Excel.
With NA the first column will be considered to contain row names under the following three conditions: (1) colNames is TRUE or contains a character vector, (2) the first column name thereof is an empty string and (3) the first data cell contains a string which is not "1".
colClasses the class of the data.frame columns. Possible entries are: double, numeric, integer, logical, character, factor, NA, isodate, isotime and isodatetime. A scalar entry will be recycled if necessary.
isodate retrieves a "YYYY-MM-DD", isotime a "hh:mm:ss" and isodatetime a "YYYY-MM-DD hh:mm:ss" character string.
With NA a suitable column type will be determined based on the first non-empty entry of the 16 rows following from (starting row).
checkNames with TRUE the colNames are guaranteed to be syntactically valid variable names (by make.names).
dateTimeAs controls how to determine a column class for columns which are formatted as date, time or datetime. Possible entries are: numeric or isodatetime. Will be overruled by explicit colClasses arguments.
stringsAsFactors set to FALSE to retrieve plain characters. The default follows the global option default.stringsAsFactors().

Details

The arguments colNames and/or colClasses can optionally include an entry for the rownames column (which will be discarded).

Value

A data.frame or a matrix of the specified type.

Pro version

By purchasing xlsReadWritePro you help support our development and maintenance effort. We are grateful that quite some people and companies did, and both, the free and pro version shall benefit (e.g. crossplatform, which is not done on a lazy afternoon...).

Features of xlsReadWritePro: + append data to existing files, + work with in-memory objects (e.g. to compose Excel reports), + work with data area subsets, + use (named) ranges and pick individual cells, + work with sheets (copy, rename, delete), + read/write formula values, + insert images, + oleDateTime classes and more datetime helper functions, + formal support.

The trial (http://www.swissr.org) is free and the two versions can easily be switched and coexist just fine. So, why not check out xlsReadWritePro and see for yourself?

!! NOTE: xlsReadWritePro works well up to R 2.9.x but not yet on R 2.10 version. The reason is, that we are currently reorganizing internal things (git/redmine/web/distr/make). We started with the free version and the pro version will follow.

See Also

write.xls, read.table, matrix, data.frame

Examples

## Not run: 
rdata <- read.xls( rfile, colNames = myc( "one", "two", "three" ), 
                   from = 3, rowNames = FALSE, type = "double" )

## there are many more examples under 'RUnitTests/test<xy>.R'

## End(Not run)

[Package xlsReadWrite version 1.5.1 Index]