Dear R helpers, I am trying to calculate the Annualized Percent Rate using following R - Code.
# ____________________________________________________________________ ## R Code library(animation) # INPUT C = 250000 # Loan Amount E = 2500 # Other Cost R = 6 # Interest rate r = R/1200 # Monthly interest rate q = 12 # No of Compoundings n = 20 # No of years # ________________________________________________________________________ # COMPUTATIONS N = n * q # No of months P = ((C + E)*r*(1+r)^N) / ((1+r)^N - 1) # Monthly Payments ani.options(nmax = 500) solu = newton.method(function(a) C * (a*(1+a)^N) - P * ((1+a)^N - 1), 1, c(R - 0.25*R, R + 0.25*R)) solu$root APR = ((1+solu$root)^q-1)*100 # _____________________________________________________________________ ## RESULTS P = 1808.988, APR = 6.298708 These are the values I obtain. # ____________________________________________________________________ ## PROBLEM This R code holds or yields results if I am dealing with only one value for each of the input. However, if there are more than one input values, how do I proceed? Say, E.g. C = c(250000, 400000) E = c(2500, 5000) R = c(6, 6) q = c(12, 12) n = c(20, 20) So using above code, I am able to obtain the values of P as 1808.988 and 2901.546 respectively. However, using this code I am not able to obtain "solu" as defined above. I tried using the tapply instead but seems its not working. Please guide as to how do I use tapply here. Regards and thanking in advance Amy [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.