问题
Weka can read csv files, however, if csv file's format is not fully satisfy Arff file standard, it may cause some problem. For example, I found loading a time series CSV file to Weka cause errors repeatedly.
There have been some posts on using python to convert csv to arff online, but I think the code is a little lengthy and not always work.
Is there a safer and quick way to convert csv to arff in R?
回答1:
Simple, use the package RWeka
library(RWeka)
write.arff(iris, file = "iris.arff")
回答2:
For Mac User (as RWeka for mac has not fixed yet):
For CSV file which cannot be loaded to Weka using CSVLoader, use R's foreign library to convert dataset from csv file to arff file
The following R code can convert a timeSeries dataset from csv into an arff file accepted by Weka
library(dplyr)
library(lubridate)
library(foreign)
byd = read.csv('byd_ready.csv')
byd %>% glimpse()
byd = byd %>% mutate(tradeDate = as.Date(tradeDate))
write.arff(byd, file='byd_R1.arff')
来源:https://stackoverflow.com/questions/40880549/how-to-write-data-frame-into-arff-using-r