I am trying to rewrite a function that I have been using for a while. Simplified this:
dat = data.table(dataframe) getRecentRow <- function(data) {
This function gives me the most recent record (with the highest time) on the ID. However, you can have multiple entries for each identifier. These entries can be distinguished by SUBID. I would like to dig one level deeper and instead of getting the most recent entries on ID, I need the most recent entries in SUBID. Since SUBIDs are not unique, the identifier must also be taken into account. So I need the most recent entry for each identifier, per SUBID.
Summing up: the input for the getRecentRow () function should not be a subset by ID, but by ID and SUBID.
I tried:
dat = data.table(dataframe) getRecentRow <- function(data) {
But this returns incorrect output, outputting more required lines. This should be an easy fix, I think I will reformulate by=list(ID, SUBID) , but I cannot figure out how to do this.
source share