How to read .arff file with R?

24,658

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

If you only care about the data and not the relations, you can just use:

read.csv("data.arff", header=FALSE, comment.char = "@")

Solution 5

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.

Share:
24,658

Related videos on Youtube

Ilya Smagin
Author by

Ilya Smagin

Updated on September 12, 2020

Comments

  • Ilya Smagin
    Ilya Smagin over 3 years

    Is there any way to do that?

    Yes, i'm new to R.

  • Ilya Smagin
    Ilya Smagin over 12 years
    Thanks! There's not much info on R in Google.
  • Andrie
    Andrie over 12 years
    @IlyaSmagin Yes there is. Search for "[R] arff" in google and your first hit is the one you want.