read.DIF {utils} | R Documentation |
Data Input from Spreadsheet
Description
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.
Usage
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 = FALSE,
transpose = FALSE, fileEncoding = "")
Arguments
file |
the name of the file which the data are to be read from, or a connection, or a complete URL. The name |
header |
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: |
dec |
the character used in the file for decimal points. |
numerals |
string indicating how to convert numbers whose conversion
to double precision would lose accuracy, see |
row.names |
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 Using |
col.names |
a vector of optional names for the variables.
The default is to use |
as.is |
controls conversion of character variables (insofar as
they are not converted to logical, numeric or complex) to factors,
if not otherwise specified by Note: In releases prior to R 2.12.1, cells marked as being of
character type were converted to logical, numeric or complex using
Note: to suppress all conversions including those of numeric
columns, set Note that |
na.strings |
a character vector of strings which are to be
interpreted as |
colClasses |
character. A vector of classes to be assumed for
the columns. Recycled as necessary, or if the character vector is
named, unspecified values are taken to be Possible values are Note that |
nrows |
the maximum number of rows to read in. Negative values are ignored. |
skip |
the number of lines of the data file to skip before beginning to read data. |
check.names |
logical. If |
blank.lines.skip |
logical: if |
stringsAsFactors |
logical: should character vectors be converted to factors? |
transpose |
logical, indicating if the row and column
interpretation should be transposed. Microsoft's Excel has been
known to produce (non-standard conforming) DIF files which would
need |
fileEncoding |
character string: if non-empty declares the
encoding used on a file (not a connection or clipboard) so the
character data can be re-encoded. See the ‘Encoding’ section
of the help for |
Value
A data frame (data.frame
) containing a representation of
the data in the file. Empty input is an error unless col.names
is specified, when a 0-row data frame is returned: similarly giving
just a header line if header = TRUE
results in a 0-row data frame.
Note
The columns referred to in as.is
and colClasses
include
the column of row names (if any).
Less memory will be used if colClasses
is specified as one of
the six atomic vector classes.
Author(s)
R Core; transpose
option by Christoph Buser, ETH Zurich
References
The DIF format specification can be found by searching on http://www.wotsit.org/; the optional header fields are ignored. See also https://en.wikipedia.org/wiki/Data_Interchange_Format.
The term is likely to lead to confusion: Windows will have a ‘Windows Data Interchange Format (DIF) data format’ as part of its WinFX system, which may or may not be compatible.
See Also
The R Data Import/Export manual.
scan
, type.convert
,
read.fwf
for reading fixed width
formatted input;
read.table
;
data.frame
.
Examples
## 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))