0

Good Evening,

I have two datasets of a shop referred to the same time period;

the first set's columns are: Date - Quantity Ordered - Initial Inventory - Final Inventory After the Order(= Column 2 + 3)

Since orders are not made on a daily basis, I completed the set with zeros, in order to have a complete series of dates.

The second set's columns are: Date - Quantity Sold.

I would like to create a dataset in which the Inventory is updated according to sales, on a daily basis, merging the two dataframes.

For example: On the 01-01-2017, Quantity Ordered = 20, Initial Inventory = 5, Final Inventory = 25, Quantity Sold = 8, Actual Inventory = 25-8 = 17;

If I compute the difference between columns, sometimes it may happen that Actual Inventory = -3, because I completed the initial date series with zeros as missing values!

Does anyone know how to address this question?

Best Regards, Alex

Alessandro Ceccarelli
  • 1,775
  • 5
  • 21
  • 41
  • 2
    Can you please post the output of `dput(head(df1, 20))` and `dput(head(df2, 20))` in your question? – Rui Barradas Sep 29 '17 at 18:29
  • 1
    You should provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data and the desired output. – MrFlick Sep 29 '17 at 18:33
  • For example: 01-01-2017, Quantity Ordered = 20, Initial Inventory = 5, Final Inventory = 25, Quantity Sold = 8, Actual Inventory = 25-8 = 17; If I compute the difference between columns, sometimes it may happen that Actual Inventory = -3, because I completed the initial date series with zeros as missing values! – Alessandro Ceccarelli Sep 29 '17 at 20:19
  • 1) structure(list(date = structure(c(16028, 16029, 16030, 16031, 16032, 16033, 16034, 16035, 16036, 16037, 16038, 16039, 16040, 16041, 16042, 16043, 16044, 16045, 16046, 16047), class = "Date"), Quantità = c(5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 5L, 3L, 0L, 0L, 6L, 4L, 4L, 4L, 0L, 0L), Giacenza_In = c(7L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 7L, 9L, 0L, 0L, 5L, 6L, 7L, 8L, 0L, 0L)), .Names = c("date", "Quantità", "Giacenza_In" ), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame" )) – Alessandro Ceccarelli Oct 17 '17 at 16:20
  • 2) . structure(list(date = structure(c(16028, 16029, 16030, 16031, 16032, 16033, 16034, 16035, 16036, 16037, 16038, 16039, 16040, 16041, 16042, 16043, 16044, 16045, 16046, 16047), class = "Date"), Venduto = c(2L, 1L, 1L, 2L, 0L, 0L, 4L, 0L, 4L, 5L, 2L, 2L, 0L, 0L, 4L, 5L, 3L, 1L, 3L, 0L)), .Names = c("date", "Venduto" ), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame" )) – Alessandro Ceccarelli Oct 17 '17 at 16:21

0 Answers0