【发布时间】:2015-07-15 13:02:47
【问题描述】:
我正在探索 SparkR 来计算分位数、平均值、类别频率等统计数据(源文件为 Amazon S3 - csv 格式)。
我能够解析 csv 文件并创建一个数据框。
但是,我无法将此 spark-dataframe 与标准 R 函数(如 quantile(), mean() 等)一起使用。
例如,这里是 R 数据框“测试”
> test <- data.frame(x=c(26,21,20),y=c(34,29,28))
> quantile ( test$x )
0% 25% 50% 75% 100%
20.0 20.5 21.0 23.5 26.0
上面的数据框产生正确的结果。但是,通过read.df() 创建的数据框不适用于quantile() 函数。
> myDf = read.df(sqlContext, "s3n://path/s3file.csv", , source="com.databricks.spark.csv")
> quantile ( myDf$column1 )
Warning messages:
1: In is.na(<S4 object of class "Column">) :
is.na() applied to non-(list or vector) of type 'S4'
2: In is.na(x) : is.na() applied to non-(list or vector) of type 'S4'
Error in x[order(x, na.last = na.last, decreasing = decreasing)] :
error in evaluating the argument 'i' in selecting a method for function '[': Error in x[!nas] : object of type 'S4' is not subsettable
我的问题很简单,有没有将 SparkR 的数据框与原生 R 函数一起使用?或者如何将 SparkR 数据帧转换为向量。
提前致谢。
【问题讨论】:
-
看起来
read.df创建了一个S4对象(example link)。
标签: r apache-spark-sql sparkr