I've been trying to use the data.table library to expand a set of dates, but I keep getting the following error:
'from' must be of length 1
date_df
transaction_id | start_date | end_date |
---|---|---|
1 | 1-5-2023 | 1-10-2023 |
2 | 2-3-2023 | 2-10-2023 |
i'm trying to get it into the following data frame:
transaction_id | start_date | end_date | current_date |
---|---|---|---|
1 | 1-5-2023 | 1-10-2023 | 1-5-2023 |
1 | 1-5-2023 | 1-10-2023 | 1-6-2023 |
1 | 1-5-2023 | 1-10-2023 | 1-7-2023 |
1 | 1-5-2023 | 1-10-2023 | 1-8-2023 |
1 | 1-5-2023 | 1-10-2023 | 1-9-2023 |
1 | 1-5-2023 | 1-10-2023 | 1-10-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-3-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-4-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-5-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-6-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-7-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-8-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-9-2023 |
2 | 2-3-2023 | 2-10-2023 | 2-10-2023 |
I used the following code:
setDT(orig_df)[, list(date = seq(from = orig_df$start_date, to = orig_df$end_Date, by = 'day')), by = transaction_id]
The code works when I use a single record, but I can't use the seq function for multiple records.
I've seen questions like this in other threads but the solutions from those threads don't seem to work and result in the error shown above.