I am working on a data frame from the following spreadsheet :enter image description here
The output of my R script should look like the second picture : enter image description here
I am translating my boss's awk code in R and the code that I have translated from awk is
new = read.csv("inputSample.csv")
if(new$Period==0)
{
print("")
prevBal = new$EndingBalance
print(new$LoanID)
print(new$EndingBalance)
}else
{
cat("else block execution")
if(new$Period < 41)
{
if(new$NumberOfClaims>0)
{
cat("executing number of claims block")
print((new$LossAmt)*(new$SimulationCount)/(new$NumberOfClaims)) #loss amount per claim
}else
{
cat("executing else aftern no. of claims that prints 0")
print(0)
}
print("end of if block point")
print(new$BalanceInClaims) #balanceinclaims
print(new$EndingBalance) #ending balance
}
}
However the output does not look like the sample that has been given to me. How do I solve this problem ?