我正在探索 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 数据帧转换为向量。
提前致谢。