0

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.

rushi
  • 225
  • 1
  • 3
  • 7
  • `seq` doesn't work that way, you can't start from two different dates. See e.g. `seq(from = 1:2, to = 3:4)`. – Axeman Mar 08 '23 at 20:28
  • Perhaps you want just `date_df[, list(date = seq(from = start_date, to = end_date, by = 'day')), by = transaction_id]` ? – Axeman Mar 08 '23 at 20:31
  • I've tried this solution but I'm getting the same error – rushi Mar 09 '23 at 20:37
  • Are you sure your dates are not strings? You do not provide your data, just tabular, but there it looks like a mdy formatted string. – Merijn van Tilborg Mar 10 '23 at 08:50

0 Answers0