r - lapply with two column arguments -


these dataframes

library(data.table) df <- fread('             account       date        nextdate                      2016-01-01     2016-02-01                      2016-02-01     2016-11-05             b          2016-03-10     2016-11-05')   ab <- fread('       date       amount      2015-06-01     55      2016-01-31     55      2016-02-28     65      2016-03-31     75') 

i want create list doing loop of each row in df , pick rows ab ab$date greater df$date , less df$nextdate output looks this:

[[1]]  date       amount 2016-01-31 55  [[2]]  date        amount 2016-02-28  65 2016-03-31  75  [[3]] date        amount 2016-03-31  75 

this attempt:

list<- lapply(df$date, function(x,y) br[date > x & date < y ],y=df$nextdate) 

create vector checks whether rows of ab meet conditions, use select rows of ab.

lapply(1:nrow(df), function(x) {   ab[which(ab$date > df[x, get("date")] & ab$date < df[x, get("nextdate")]), ] }) 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -