如何在 sparkR 中对日期进行过滤

How to make the filter function on dates in sparkR

'u' 是一个包含 ID = 1, 2, 3 .. and time= "2010-01-01", "2012-04-06", .. ID 和时间的类型为字符串。我将时间类型转换为 'Date'

u$time <- cast(u[[2]], "Date")

我现在想要你的第一次。

first <- first(u$time)

我现在在第一次的基础上增加 150 天来创建一个新的时间

cluster<- first+150

我现在想做一个子集。我想要一个新的 'u',时间是前 150 天的时间。

ucluster <- filter(u, u$time < cluster)

但这不能在 sparkR 中 运行。我收到此消息 "returnstatus==0 is not TRUE"。

您的方法的问题在于 ucluster 是一个项目的列,而不是日期。如果你拿第一行并首先存储它的时间,一切正常:

df <- data.frame(ID=c(1,2,3,4),time=c("2010-01-01", "2012-04-06", "2010-04-12", "2012-04-09"))
u  <- createDataFrame(sqlContext,df)

u$time  <- cast(u[[2]], "Date")
first   <- take(u,1)$time
cluster <- first + 150

ucluster <- filter(u, u$time < cluster)

collect(ucluster)