Data Input from Spreadsheet
Reads a file in Data Interchange Format (DIF) and creates a data frame from it. DIF is a format for data matrices such as single spreadsheets.
read.DIF(file, header = FALSE, dec = ".", numerals = c("allow.loss", "warn.loss", "no.loss"), row.names, col.names, as.is = !stringsAsFactors, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, blank.lines.skip = TRUE, stringsAsFactors = default.stringsAsFactors(), transpose = FALSE, fileEncoding = "")
- the name of the file which the data are to be read from,
or a connection, or a complete URL.
"clipboard"may also be used on Windows, in which case
read.DIF("clipboard")will look for a DIF format entry in the Windows clipboard.
- a logical value indicating whether the spreadsheet contains the
names of the variables as its first line. If missing, the value is
determined from the file format:
headeris set to
TRUEif and only if the first row contains only character values and the top left cell is empty.
- the character used in the file for decimal points.
- string indicating how to convert numbers whose conversion
to double precision would lose accuracy, see
- a vector of row names. This can be a vector giving
the actual row names, or a single number giving the column of the
table which contains the row names, or character string giving the
name of the table column containing the row names.
If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if
row.namesis missing, the rows are numbered.
row.names = NULLforces row numbering.
- a vector of optional names for the variables.
The default is to use
"V"followed by the column number.
- the default behavior of
read.DIFis to convert character variables to factors. The variable
as.iscontrols the conversion of columns not otherwise specified by
colClasses. Its value is either a vector of logicals (values are recycled if necessary), or a vector of numeric or character indices which specify which columns should not be converted to factors.
Note: In releases prior to R
- A data frame (
data.frame) containing a representation of the data in the file. Empty input is an error unless
col.namesis specified, when a 0-row data frame is returned: similarly giving just a header line if
header = TRUEresults in a 0-row data frame.
The columns referred to in
the column of row names (if any).
Less memory will be used if
colClasses is specified as one of
the six atomic vector classes.
- R Data Import/Export Manual
The DIF format specification can be found by searching on
The term is likely to lead to confusion: Windows will have a
The R Data Import/Export manual.
## read.DIF() may need transpose = TRUE for a file exported from Excel udir <- system.file("misc", package = "utils") dd <- read.DIF(file.path(udir, "exDIF.dif"), header = TRUE, transpose = TRUE) dc <- read.csv(file.path(udir, "exDIF.csv"), header = TRUE) stopifnot(identical(dd, dc), dim(dd) == c(4,2))