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
.
.
.