【问题标题】:passing rows of a dataframe as a selection parameter to rxdatastep将数据帧的行作为选择参数传递给 rxdatastep
【发布时间】:2016-12-18 12:10:08
【问题描述】:

我有一个这样的数据框:

> DataSet_Fehler
    Ohne_Verschiebung    Mit_Verschiebung
1 2016-08-29 19:15:48 2016-08-29 19:19:34
2 2016-08-30 19:38:24 2016-08-30 19:42:18
3 2016-10-28 10:39:24 2016-10-28 10:42:48
4 2016-11-07 19:12:18 2016-11-07 19:15:45

我想根据这个数据框过滤我的 xdf 文件(如果我用 SQL 解释的话):

SELECT *
   FROM Myxdf_file
   Where DataSet_Fehler[i,]$Ohne_Verschiebung < Date < DataSet_Fehler[i,]$Mit_Verschiebung

我认为transformFunc 可能是我的解决方案,但我不确定,但我不知道如何实现它:

Filter_row<-function(DataSet_Fehler)
{
  return(DataSet_Fehler)
}
rxDataStep(inData = MyData,  transformFunc = Filter_row)

我该怎么做?

【问题讨论】:

  • 一个可重现的例子会很棒。

标签: r microsoft-r


【解决方案1】:

您可以将一个函数传递给rxDataSteprowSelection 参数,该函数引用您的数据框:

# dates on which to filter your data
filterDf <- read.csv(text=
"2016-08-29 19:15:48, 2016-08-29 19:19:34
2016-08-30 19:38:24, 2016-08-30 19:42:18
2016-10-28 10:39:24, 2016-10-28 10:42:48
2016-11-07 19:12:18, 2016-11-07 19:15:45
", header=FALSE, colClasses="POSIXct")

# your xdf file
indf <- read.csv(text="dt
2016-08-29 19:16:00
2016-08-29 19:20:00
2016-08-30 19:40:00
2016-09-01 12:00:00
2016-11-07 19:14:00
", colClasses="POSIXct")
inxdf <- rxDataStep(indf, "inxdf.xdf")

rowFilter <- function(x, filterDf)
{
    start <- filterDf[[1]]
    end <- filterDf[[2]]
    vapply(x, function(x) any(start < x & x < end), FUN.VALUE=logical(1))
}

rxDataStep(inxdf,
           rowSelection=fil(dt, filDf),
           transformObjects=list(fil=rowFilter, filDf=filterDf))
#                   dt
#1 2016-08-29 19:16:00
#2 2016-08-30 19:40:00
#3 2016-11-07 19:14:00

【讨论】:

  • 这个需要哪个包?
  • 这个包叫做 RevoScaleR,如果你有 Microsoft R Server 或 Microsoft R Client,你就有了。否则,您可以download it.
  • 谢谢!我会调查的。
猜你喜欢
  • 2021-03-12
  • 2020-05-28
  • 2012-08-31
  • 2017-12-16
  • 1970-01-01
  • 2013-01-27
  • 2023-03-28
相关资源
最近更新 更多