EVOLUTION-MANAGER
Edit File: read.DIF.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Data Input from Spreadsheet</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for read.DIF {utils}"><tr><td>read.DIF {utils}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Data Input from Spreadsheet</h2> <h3>Description</h3> <p>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. </p> <h3>Usage</h3> <pre> 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 = "") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>file</code></td> <td> <p>the name of the file which the data are to be read from, or a <a href="../../base/html/connections.html">connection</a>, or a complete URL. </p> <p>The name <code>"clipboard"</code> may also be used on Windows, in which case <code>read.DIF("clipboard")</code> will look for a DIF format entry in the Windows clipboard. </p> </td></tr> <tr valign="top"><td><code>header</code></td> <td> <p>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: <code>header</code> is set to <code>TRUE</code> if and only if the first row contains only character values and the top left cell is empty.</p> </td></tr> <tr valign="top"><td><code>dec</code></td> <td> <p>the character used in the file for decimal points.</p> </td></tr> <tr valign="top"><td><code>numerals</code></td> <td> <p>string indicating how to convert numbers whose conversion to double precision would lose accuracy, see <code><a href="type.convert.html">type.convert</a></code>.</p> </td></tr> <tr valign="top"><td><code>row.names</code></td> <td> <p>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. </p> <p>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 <code>row.names</code> is missing, the rows are numbered. </p> <p>Using <code>row.names = NULL</code> forces row numbering. </p> </td></tr> <tr valign="top"><td><code>col.names</code></td> <td> <p>a vector of optional names for the variables. The default is to use <code>"V"</code> followed by the column number.</p> </td></tr> <tr valign="top"><td><code>as.is</code></td> <td> <p>the default behavior of <code>read.DIF</code> is to convert character variables to factors. The variable <code>as.is</code> controls the conversion of columns not otherwise specified by <code>colClasses</code>. 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. </p> <p>Note: In releases prior to <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 2.12.1, cells marked as being of character type were converted to logical, numeric or complex using <code><a href="type.convert.html">type.convert</a></code> as in <code><a href="read.table.html">read.table</a></code>. </p> <p>Note: to suppress all conversions including those of numeric columns, set <code>colClasses = "character"</code>. </p> <p>Note that <code>as.is</code> is specified per column (not per variable) and so includes the column of row names (if any) and any columns to be skipped. </p> </td></tr> <tr valign="top"><td><code>na.strings</code></td> <td> <p>a character vector of strings which are to be interpreted as <code><a href="../../base/html/NA.html">NA</a></code> values. Blank fields are also considered to be missing values in logical, integer, numeric and complex fields.</p> </td></tr> <tr valign="top"><td><code>colClasses</code></td> <td> <p>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 <code>NA</code>. </p> <p>Possible values are <code>NA</code> (when <code><a href="type.convert.html">type.convert</a></code> is used), <code>"NULL"</code> (when the column is skipped), one of the atomic vector classes (logical, integer, numeric, complex, character, raw), or <code>"factor"</code>, <code>"Date"</code> or <code>"POSIXct"</code>. Otherwise there needs to be an <code>as</code> method (from package <span class="pkg">methods</span>) for conversion from <code>"character"</code> to the specified formal class. </p> <p>Note that <code>colClasses</code> is specified per column (not per variable) and so includes the column of row names (if any). </p> </td></tr> <tr valign="top"><td><code>nrows</code></td> <td> <p>the maximum number of rows to read in. Negative values are ignored.</p> </td></tr> <tr valign="top"><td><code>skip</code></td> <td> <p>the number of lines of the data file to skip before beginning to read data.</p> </td></tr> <tr valign="top"><td><code>check.names</code></td> <td> <p>logical. If <code>TRUE</code> then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names. If necessary they are adjusted (by <code><a href="../../base/html/make.names.html">make.names</a></code>) so that they are, and also to ensure that there are no duplicates.</p> </td></tr> <tr valign="top"><td><code>blank.lines.skip</code></td> <td> <p>logical: if <code>TRUE</code> blank lines in the input are ignored.</p> </td></tr> <tr valign="top"><td><code>stringsAsFactors</code></td> <td> <p>logical: should character vectors be converted to factors?</p> </td></tr> <tr valign="top"><td><code>transpose</code></td> <td> <p>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 <code>transpose = TRUE</code> to be read correctly.</p> </td></tr> <tr valign="top"><td><code>fileEncoding</code></td> <td> <p>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 <code><a href="../../base/html/connections.html">file</a></code>, the ‘R Data Import/Export Manual’ and ‘Note’.</p> </td></tr> </table> <h3>Value</h3> <p>A data frame (<code><a href="../../base/html/data.frame.html">data.frame</a></code>) containing a representation of the data in the file. Empty input is an error unless <code>col.names</code> is specified, when a 0-row data frame is returned: similarly giving just a header line if <code>header = TRUE</code> results in a 0-row data frame. </p> <h3>Note</h3> <p>The columns referred to in <code>as.is</code> and <code>colClasses</code> include the column of row names (if any). </p> <p>Less memory will be used if <code>colClasses</code> is specified as one of the six atomic vector classes. </p> <h3>Author(s)</h3> <p>R Core; <code>transpose</code> option by Christoph Buser, ETH Zurich</p> <h3>References</h3> <p>The DIF format specification can be found by searching on <a href="http://www.wotsit.org/">http://www.wotsit.org/</a>; the optional header fields are ignored. See also <a href="https://en.wikipedia.org/wiki/Data_Interchange_Format">https://en.wikipedia.org/wiki/Data_Interchange_Format</a>. </p> <p>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. </p> <h3>See Also</h3> <p>The <em>R Data Import/Export</em> manual. </p> <p><code><a href="../../base/html/scan.html">scan</a></code>, <code><a href="type.convert.html">type.convert</a></code>, <code><a href="read.fwf.html">read.fwf</a></code> for reading <em>f</em>ixed <em>w</em>idth <em>f</em>ormatted input; <code><a href="read.table.html">read.table</a></code>; <code><a href="../../base/html/data.frame.html">data.frame</a></code>. </p> <h3>Examples</h3> <pre> ## 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)) </pre> <hr /><div style="text-align: center;">[Package <em>utils</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>