
Last chance! 50% off unlimited learning
Sale ends in
write
and the S4 methods to
write transactions or associations (itemsets, rules) to disk.
write(x, file = "",...)
"write"(x, file="", format = c("basket", "single"), sep=" ", quote=TRUE, ...)
"write"(x, file="", sep=" ", quote=TRUE, ...)
quote=TRUE
and
sep=","
for saving data as in csv format.write.table
or write
. Use fileEncoding
to set the encoding used for
writing the file.write
first uses coercion
to data.frame to obtain a printable form of
x
and then uses write.table
to write the data to disk.Transactions can be saved in basket (one line per transaction) or in single (one line per item) format.
Note: To save and load associations in compact form, use save
and
load
from the base package. Alternatively, association can be
written to disk in PMML (Predictive Model Markup Language)
via write.PMML
. This requiresvpackages pmml.
read.transactions
for reading transactions from a file,
read.PMML
and write.PMML
for reading/writing associations in PMML format,
write.table
(in base),
transactions-class
,
associations-class
data("Epub")
## write the formated transactions to screen (basket format)
write(head(Epub))
## write the formated transactions to screen (single format)
write(head(Epub), format="single")
## write the formated result to file in CSV format
write(Epub, file = "data.csv", format="single", sep = ",")
## write rules in CSV format
rules <- apriori(Epub, parameter=list(support=0.0005, conf=0.8))
write(rules, file = "data.csv", sep = ",")
unlink("data.csv") # tidy up
Run the code above in your browser using DataLab