我想知道sparkR是否更容易合并大数据集而不是“常规R”?我有12个csv文件,大约500,000行40列。这些文件是2014年的月度数据。我想为2014年制作一个文件。这些文件都具有相同的列标签,我希望按第一列(年)合并。但是,有些文件比其他文件有更多的行。使用sparkR合并大数据集
当我运行下面的代码:
setwd("C:\\Users\\Anonymous\\Desktop\\Data 2014")
file_list <- list.files()
for (file in file_list){
# if the merged dataset doesn't exist, create it
if (!exists("dataset")){
dataset <- read.table(file, header=TRUE, sep="\t")
}
# if the merged dataset does exist, append to it
if (exists("dataset")){
temp_dataset <-read.table(file, header=TRUE, sep="\t")
dataset<-rbind(dataset, temp_dataset)
rm(temp_dataset)
}
}
[R坠毁。
当我运行这段代码:
library(SparkR)
library(magrittr)
# setwd("C:\\Users\\Anonymous\\Desktop\\Data 2014\\Jan2014.csv")
sc <- sparkR.init(master = "local")
sqlContext <- sparkRSQL.init(sc)
Jan2014_file_path <- file.path('Jan2014.csv')
system.time(
housing_a_df <- read.df(sqlContext,
"C:\\Users\\Anonymous\\Desktop\\Data 2014\\Jan2014.csv",
header='true',
inferSchema='false')
)
我得到了以下错误:
Error in invokeJava(isStatic = TRUE, className, methodName, ...) :
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 0.0 (TID 0, localhost):
那么这将是在sparkR合并这些文件一个简单的方法?
你读过[this](http://stackoverflow.com/questions/23169645/r-3-0-3-rbind-multiple-csv-files)吗?在第一节中,'file_list'csv文件中的所有文件是? –
你说你想“按第一列合并”,但在你的示例代码中,你连接了来自不同文件的行。下面的答案(在撰写本文时)是关于合并=连接,而不是连接。 – kasterma
请问下面有答案,回答你的问题?如果是,请接受答案。这可能有助于其他开发人员 – sag