I'd like to accomplish something very similar to what is being done in this question. I have a large data.table (or data.frame) with a single column that has a Base Time Stamp (BST). I'd need to determine number of days for each of the unique IDs which may be many tens of thousands of rows. All the lubridate tutorials I'm finding start with the very simple start to end example... (this is a great intro but not the answer I'm looking for).
I basically need to loop through my BST column and identify a start and end date for each ID.
Here is example data:
library(data.table)
myID <- c(1,1,1,1,1,1,2,2,2,2,2,2)
BST <- c("2017-06-01 00:00:01", "2017-06-01 00:00:02",
"2017-06-02 00:00:01", "2017-06-02 00:00:02",
"2017-06-03 00:00:01", "2017-06-03 00:00:02",
"2017-06-01 00:00:01", "2017-06-01 00:00:02",
"2017-06-03 00:00:01", "2017-06-03 00:00:02",
"2017-06-05 00:00:01", "2017-06-05 00:00:02")
V3 <- c("a", "a", "a", "a", "a", "a", "b", "b", "b","b", "b", "b")
dt1 <- data.table(myID, BST, V3)
And desired result:
And then how is it accomplished while keeping all the original rows... a la dplyr::mutate() ?
Second desired result: