简体   繁体   中英

how to calculate the sum of the sales figures the previous 5 days with rstudio so the forecast?

I have a table in Rstudio and my table had 4 attributes and I want to know how to calculate the forecast for example the sum of the sales in the previous 5 days

Something tells me that this is from a school-assignement, so I won't give you the entire answer.

Say your table looks somewhat like this

id date sales
1 2021-12-30 100
2 2021-12-31 110
3 2022-01-01 120
4 2022-02-01 130
5 2022-03-01 140
6 2022-04-01 150
7 2022-05-01 160

The algorithm for computing the sum of the last five days, say between 2021-12-31 and 2022-01-04, would be something a long the lines of

  1. Filter away all rows that have date < 2021-12-31
  2. Filter away all rows that have date > 2021-01-04
  3. Use a sum-function on the sales-column on the remaining table.

If you can use dplyr , you could probably do everything in two lines of code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM