I created a dataframe:
totalDeposit <- cumsum(testd$TermDepositAMT[s1$ix])
which is basically calculating cumulative sum of TermDeposit
amounts in testd
dataframe and storing it in totalDeposit
. This works perfectly ok.
I then need to calculate the average of the deposit amount and I use the following code:
avgDeposit <- totalDeposit / (1:testd)
But I get an error message:
Error in 1:testd : NA/NaN argument
In addition: Warning message:
In 1:testd : numerical expression has 19 elements: only the first used
testd has some 8000 observations and 19 variables.
Could someone help me get past this issue? I've attempted to locate this error message online but all I have understood so far is that 1:testd basically makes R read testd as a number which it isn't and hence I get an error message. Would simply taking mean(totalDeposit)
do the trick? I tried it but the figure I get is absurd and nowhere representative of the average.
Thank you for your help.