【问题标题】:How to make the filter function on dates in sparkR如何在 sparkR 中对日期进行过滤功能
【发布时间】:2015-08-27 14:01:01
【问题描述】:

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

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”。

【问题讨论】:

    标签: sparkr


    【解决方案1】:

    您的方法的问题是 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多