Folks,
The following function works like a charm!

> #Amortization for multiple rows
> createAmorts<-function(ams, numPer, term) {
>   fctrs<-rep(1:term, each = numPer)
>   
>   oneRow<-function(am,  fac){      
>     tdf<-data.frame(ams = c(am), yrs=fac)      
>     agg<-aggregate(ams ~ yrs, data = tdf, sum)     
>     agg$ams<-1-cumsum(agg$ams)     
>     agg     
>   }     
>   data.frame(id = rep(1:nrow(ams), each = term),
>              do.call(rbind, apply(ams, 1, oneRow, fctrs)))
> }

But when I run the function inside some other code:
> retrieveSSdata<-function(inputPath) {
>   iList<-list()
>   theWb<-loadWorkbook(inputPath)
>   
>   # Set up the amorts using inputs and term and frequency
>   theTerm<-readNamedRegion(theWb, "Term", useCachedValues = TRUE, header = 
> FALSE)
>   theFreq<-readNamedRegion(theWb, "freq", useCachedValues = TRUE, header = 
> FALSE)
>   allAmorts<-readNamedRegion(theWb, "allAmorts", useCachedValues = TRUE, 
> header = FALSE)

>   theAmorts<-createAmorts(allAmorts, 12/theFreq, theTerm*theFreq)

>   iList[["amort"]]<-theAmorts
>   iList[["PremAttach"]]<-readNamedRegion(theWb, "amPremAttach", 
> useCachedValues = TRUE)
>   #
>   
>   iList
> }


> Note that in the above code everything seems to work fine except for the 
> “createAmorts" code.



I have the following packages loaded:
require(XLConnect)
require(plyr)
require(sm)
require(fOptions)
require(fCopulae)

I have spent a lot of time on this to no avail.

Any help would be appreciated.

Best,
KW

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to