read.transactions.html

来自「本程序是基于linux系统下c++代码」· HTML 代码 · 共 115 行

HTML
115
字号
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Read Transaction Data</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../R.css">
</head><body>

<table width="100%" summary="page for read.transactions {arules}"><tr><td>read.transactions {arules}</td><td align="right">R Documentation</td></tr></table>
<h2>Read Transaction Data</h2>


<h3>Description</h3>

<p>
Reads a transaction data file from disk and creates a
<code><a href="transactions-class.html">transactions</a></code> object.
</p>


<h3>Usage</h3>

<pre>
read.transactions(file, format = c("basket", "single"), sep = NULL,
                  cols = NULL, rm.duplicates = FALSE)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>file</code></td>
<td>
the file name.</td></tr>
<tr valign="top"><td><code>format</code></td>
<td>
a character string indicating the format of the data
set.  One of <code>"basket"</code> or <code>"single"</code>, can be
abbreviated.</td></tr>
<tr valign="top"><td><code>sep</code></td>
<td>
a character string specifying how fields are separated in
the data file, or <code>NULL</code> (default).  For basket format, this
can be a regular expression; otherwise, a single character must be
given.  The default corresponds to white space separators.</td></tr>
<tr valign="top"><td><code>cols</code></td>
<td>
For the &lsquo;single&rsquo; format, <code>cols</code> is a 
numeric vector of length two giving the numbers of the
columns (fields) with the transaction and item ids, respectively.
For the &lsquo;basket&rsquo; format, <code>cols</code> can be a numeric scalar
giving the number of the column (field) with the transaction ids.
If <code>cols = NULL</code></td></tr>
<tr valign="top"><td><code>rm.duplicates</code></td>
<td>
a logical value specifying if duplicate items should
be removde from the transactions.</td></tr>
</table>

<h3>Details</h3>

<p>
For &lsquo;basket&rsquo; format, each line in the transaction data file
represents a transaction where the items (item labels) are separated
by the characters specified by <code>sep</code>.  For &lsquo;single&rsquo;
format, each line corresponds to a single item, containing at least
ids for the transaction and the item.
</p>


<h3>Value</h3>

<p>
Returns an object of class
<code><a href="transactions-class.html">transactions</a></code>.</p>

<h3>See Also</h3>

<p>
<code><a href="transactions-class.html">transactions-class</a></code>
</p>


<h3>Examples</h3>

<pre>
## create a demo file using basket format for the example
data &lt;- paste("item1,item2","item1","item2,item3", sep="\n")
cat(data)
write(data, file = "demo_basket")

## read demo data
tr &lt;- read.transactions("demo_basket", format = "basket", sep=",")
inspect(tr)

## create a demo file using single format for the example
## column 1 contains the transaction ID and column 2 contains one item
data &lt;- paste("trans1 item1", "trans2 item1","trans2 item2", sep ="\n")
cat(data)
write(data, file = "demo_single")

## read demo data
tr &lt;- read.transactions("demo_single", format = "single", cols = c(1,2))
inspect(tr)

## tidy up
unlink("demo_basket")
unlink("demo_single")

</pre>



<hr><div align="center">[Package <em>arules</em> version 0.6-6 <a href="00Index.html">Index]</a></div>

</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?