How to read .arff file with R?
Is there any way开发者_如何学C to do that?
Yes, i'm new to R.
read.arff
in package foreign
reads data from Weka Attribute-Relation File Format (ARFF) files.
Update: there is a new package on CRAN:
farff: A Faster 'ARFF' File Reader and Writer
In general the answer to questions like this can be found via the sos
package, which accesses a full-text search of all the packages on CRAN.
install.packages("sos")
library("sos")
findFn("arff")
finds functions in the foreign
(as noted above) and RWeka
packages. Since foreign
is a recommended package, it will be installed on your system by default. Hence you would have found the answer with
help.search("arff")
in the first place, without installing the sos
package. sos
is still worth having for times when the string you are searching for isn't in the metadata (title, keywords, alias, etc.), which is all that help.search
searches, or not in a package you already have installed on your system (ditto). (Looking through the R Data Import/Export Manual, which also comes with your system, is generally useful but would not have found the answer to this question ...)
It might be useful to know about the RWeka
version on the off chance that the version in foreign
(which you should try first) fails for some reason.
Even though this question is already answered I realize there is another noteworthy solution. Check the RWeka
package that enables you to read and write arff
files. Plus it gives you a wrapper for Weka
functions. So you could use Weka functionality without installing Weka itself (though it installs .jars). See also this doku -> read.arff
.
If you only care about the data and not the relations, you can just use:
read.csv("data.arff", header=FALSE, comment.char = "@")
The easiest way to do it is using the "RWeka"
library which has read.arff()
function that reads .arff
files.
library(RWeka)
test=read.arff("../Test/test.arff")
Hope this helps.
精彩评论