Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

How to re-arrange data in a data frame in R?

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>