I am trying to do something in R that is equivalent to a "first value" windowing function in SQL, such as:
select *, first_value(value3) over (partition by value1, value2 order by value5 desc)
from df
Is there a good way to do this in R without having to create a database to use something like sqldf/RPostgreSQL?
I've seen some other examples like the answers here: Cumulative sum by group in sqldf?
but I'm having some trouble figuring out how to do it with a function where the order within the window matters. Another thing is that I'm working with ~500K rows, and so performance is an concern.
Edit: here's an example:
item_id rental_date customer_id
I001 10/20/2012 1
I002 10/05/2012 4
I001 10/15/2012 3
I004 10/19/2012 1
I001 10/11/2012 6
I002 9/15/2012 5
I004 10/13/2012 10
I001 9/30/2012 4
How would I determine the first customer to rent a given item for each month?