0

Actual OutputI have loop that runs fine that sums the amount of a column based on the range of some dates. This loop is as follows:

 Sd <- as.Date('2017-01-01',tz = "GMT")
 EndDate <- as.Date('2017-01-20',tz = "GMT")
 Ed <- EndDate + 10


 while (Sd < Ed) {


 Sd <- Sd + 1
 LTV1 <- LTV %>% group_by(InstallationDate)%>% filter(z < Sd) %>% 
 summarize(Amount = sum(USAmount))


   }
 mn <-   as.data.frame(LTV1)

In the above, Z is a column containing dates. Now i want to create a column for each day that the above loop runs, with each column indicating the amount collected that particular day. So in this case we would need 30 columns.

I have tried creating another loop that will be creating a column for each day, but it does nothing, and the output is still the same. Code is as follows:

  Sd <- as.Date('2017-01-01',tz = "GMT")
  EndDate <- as.Date('2017-01-20',tz = "GMT")
  Ed <- EndDate + 10

  V <- Ed - Sd  

  for(i in 1:V){


  mn[ , paste0("Amount", i)] <-   while (Sd < Ed) {


  Sd <- Sd + 1
  LTV1 <- LTV %>% group_by(InstallationDate)%>% filter(z < Sd) %>% 
  summarize(Amount = sum(USAmount))

 }

 }

 mn <-   as.data.frame(LTV1)

This does not work at all, although it runs. I am not sure what i am doing wrong or what the fix is. I would be grateful for any feedback since i am quit stuck. Desirable outcome will be:

 InstallationDate     Amount1   Amount2  Amount3 ...........Amount30
 2017-01-01             
 2017-01-02             
     .
     . 
     .
  • Please don't keep posting the same question, again and again. Edit your previous questions for clarity. As I asked on your last post, **please** post a few rows of actual sample ouput for your sample input, that will make it make sense. – Gregor Thomas Apr 22 '19 at 20:29
  • Hi Gregor, i have posted the output when you run the code for 10 days. Now i have the summed amount after 10 days. However i would like for each day to be summed cumulatively, in separate columns. So i would need an extra 9 columns. The 10th column should much the column "Amount" in the screenshot i have posted. – Xristos Solwmou Apr 22 '19 at 20:42
  • Please comment and edit your previous question that is still open, – Gregor Thomas Apr 22 '19 at 20:52

0 Answers0