How to read .arff file with R?
Asked Answered
A

5

30

Is there any way to do that?

Yes, i'm new to R.

Amphictyony answered 25/9, 2011 at 20:1 Comment(0)
J
42

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

Jackinthepulpit answered 25/9, 2011 at 20:7 Comment(0)
V
26

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.

Vickery answered 25/9, 2011 at 20:20 Comment(2)
Thanks! There's not much info on R in Google.Amphictyony
@IlyaSmagin Yes there is. Search for "[R] arff" in google and your first hit is the one you want.Eiderdown
V
10

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.

Vestment answered 3/11, 2011 at 21:21 Comment(0)
C
7

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

read.csv("data.arff", header=FALSE, comment.char = "@")
Crowning answered 15/5, 2015 at 18:13 Comment(0)
S
6

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.

Sarraute answered 18/2, 2016 at 2:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.