将数据帧的行作为选择参数传递给rxdatastep

时间:2016-12-18 12:10:09

标签: r microsoft-r

我有一个这样的数据框:

> 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)

我该怎么做?

1 个答案:

答案 0 :(得分:3)

您可以将函数传递给引用您的数据框的rowSelection rxDataStep参数:

# 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