Many thanks to Patrick Agin and Dimitris Rizopoulos.
Dimitri said...
you can try something like this:
data$out <- data$T0 * sapply(data$Age, function(i, r.) sum((1 +
r)^(1:i)), r. = r)
Patrick said...
A geometric series a + as + as^2 + ... + as^(n-1)
can be written as
(a-s.k)/(1-s) where k = a.s^(n-1)
For your specific problem, try:
k <- data[,"T0"]*(1+r)^data[,"Age"]
data[,4] <- -(data[,"T0"]-(1+r)*k)/r-data[,"T0"]
hope this helps,
Patrick Agin
--
Laboratoire Central des Ponts et Chaussées
[Division ESAR ? Section AGR]
Route de Bouaye BP 4129
44341 Bouguenais Cedex
France
Tél 33 (0)2 40 84 56 18
Fax 33 (0)2 40 84 59 92
|