Dear Sir,

Thanks a lot for your advice and surely I will be going through your suggestion as regards  ?optim. In the mean time, is it possible to guide me regarding one general question. 

Suppose instead of using newton.method function, I am using some other function resulting in some other process and which is using say C, E, N, R only. (i.e. I am not calculating root anymore). My problem is how do I apply this function row-wise to a table.

I am not sure whether I am able to put up my query properly. Basically, I need to apply the function to a table and store the result row-wise.

Thanks in advance Sir.

Regards

Amy

--- On Mon, 10/25/10, Dennis Murphy <djmuser@gmail.com> wrote:

From: Dennis Murphy <djmuser@gmail.com>
Subject: Re: [R] Using tapply?
To: "Amy Milano" <milano_amy@yahoo.com>
Cc: r-help@r-project.org
Date: Monday, October 25, 2010, 10:47 AM

Hi:

I'm pretty sure that newton.method in the animation package is meant to illustrate the technique rather than to be used as an optimizer in practice. Look at ?optim; it that doesn't meet your needs, consult the Optimization Task View at CRAN, where you will find several packages, in addition to functions in the base package, devoted to function optimization.


HTH,
Dennis

On Mon, Oct 25, 2010 at 12:18 AM, Amy Milano <milano_amy@yahoo.com> wrote:

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.







      
	[[alternative HTML version deleted]]

