Apache spark SparkR中的移动平均线

Apache spark SparkR中的移动平均线,apache-spark,sparkr,Apache Spark,Sparkr,我需要使用Spark上的R对大型timeseries数据集进行移动平均 我看到在Scala和Java中有这样的实现: , 但是在R中,我没有使用SparkR窗口函数解决这个问题。我使用的是Spark 2.0 btw set.seed(123) #generate poisson distribution for easy checking, with lambda = 15 n <- 1000 orderingColumn = seq(1,n) data = rpois(n, 15)

我需要使用Spark上的R对大型timeseries数据集进行移动平均

我看到在Scala和Java中有这样的实现: ,
但是在R

中,我没有使用SparkR窗口函数解决这个问题。我使用的是Spark 2.0 btw

set.seed(123)

#generate poisson distribution for easy checking, with lambda = 15
n <- 1000
orderingColumn = seq(1,n)
data = rpois(n, 15)
df <- data.frame(orderingColumn, data)

#Create sparkdf
sdf <- as.DataFrame(df); 

#Moving average
ws <- windowOrderBy(sdf$orderingColumn)
frame <- rowsBetween(ws, -100, 0) #100 observations back included in average
sdfWithMa <- withColumn(sdf, "moving_average", over(avg(sdf$data), frame))

head(sdfWithMa, 100)
set.seed(123)
#生成泊松分布,便于检查,λ=15
N
ws <- orderBy(windowPartitionBy("my_partition_column"), sdf$orderingColumn)