[R] Alternative to aggregate and cbind

Alexander.Hener@daimlerchrysler.com Alexander.Hener at daimlerchrysler.com
Fri May 17 10:56:34 CEST 2002


Hello group,

this problem can be solved with the code below, but it feels a little clumsy. 
Any suggestions on making it more efficient are appreciated.
What I want is to compute for each value of StandExposure the sum of all 
corresponding PD values. These sums should then be multiplied by the 
corresponding value of StandExposure, and everything be summarised in a 
separate matrix, Band.

 
Band <- aggregate(Portfolio$PD,list(StandExposure=Portfolio$StandExposure),sum)

Band <- 
cbind(Band,aggregate(Portfolio$StandExposure,list(StandExposure=Portfolio$StandE
xposure),mean))

Band <- cbind(as.vector(Band[,2]),as.vector(Band[,4]))

Band <- cbind(Band,Band[,1]*Band[,2])


Thanks in advance,

Alexander Hener.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list