readDataFrame | R Documentation |
Reads data from a tabular file or a set of such files.
## Default S3 method:
readDataFrame(filename, path=NULL, ...)
filename , path |
|
... |
Additional arguments passed to either
(i) |
When reading multiple files at once, first each file is read into
a data.frame
, and then these data.frame
s are (by default) merged into
one data.frame
using rbind
(). This requires that the
same set of columns are read for each file. Which columns to read
can be controlled by specifying their names in
argument colClasses
. To change how the data.frame
s are
merged, use argument combineBy
.
For more information, follow the help on the above to
readDataFrame()
help links.
Returns a data.frame
.
Henrik Bengtsson
read.table
.
For further details, see classes TabularTextFile
and
TabularTextFileSet
.
path <- system.file("exData/dataSetA,original", package="R.filesets")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example: Standard tab-delimited file with header comments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- file.path(path, "fileA,20100112.dat")
# Read all data
df <- readDataFrame(pathname)
print(df)
# Read columns 'x', 'y', and 'char'
df <- readDataFrame(pathname, colClasses=c("(x|y)"="integer", "char"="character"))
print(df)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example: Tab-delimited file with header comments but
# also two garbage at the very beginning
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- file.path(path, "fileA,20130116.datx")
# Explicitly skip the two rows
df <- readDataFrame(pathname, skip=2)
print(df)
# Skip until the first data row
df <- readDataFrame(pathname, skip="^x")
print(df)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example: Tab-delimited file without column header
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- system.file("exData/dataSetB", package="R.filesets")
pathname <- file.path(path, "fileF,noHeader.dat")
# Incorrectly assuming column header
df <- readDataFrame(pathname)
print(df)
# No column header
df <- readDataFrame(pathname, header=FALSE)
print(df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.