#================================================================#----------------------------------------------------------------# Step0: Assigning values to individual variables # P: Principal # M: Total month of repayment # I: Annual interest rate # s: Monthly interest rate P=25000I=0.05m= -s=i/ A# Step1: Calculates the month vector T=1: m# Step2: Calculates the monthly repayment amount Monthly.payment= (1+s) ^m*s*p/((1+s) ^m-1) # Step3: Calculates the principal amount to be repaid per month principal.paid.money.t= (1+s) ^ (t1) *s*p/(1+s) ^m-1) # Step4: Calculates the monthly outstanding principal amount Vector principal.remaining= p* (1-((1+s) ^t-1)/((1+s) ^m-1)) # step5: The monthly repayment amount is deducted from the monthly principal quota, and the interest interest.paid.month.t per month is calculated .= Monthly.payment-principal.paid.money.t# Step6: Accumulate the interest paid per month and calculate the total interest Total.interest.paid=sum(interest.paid.month.t) # step7: Displays calculation results monthly.paymenttotal.interest.paidtprincipal.paid.money.tinterest.paid.month.tprincipal.remaining the console # Step8: Plots plot (T,principal.remaining,type) with the non-repaid principal amount vector as the vertical axis for the month vector .="L")
Selected from the "R Language Beginner's Guide"
R Language loan Monthly data analysis