How to write data.frame into arff using R

痞子三分冷 提交于 2019-12-12 04:33:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!