Skip to content

Please Please Please Help me!!

3 messages · Madhavi Bhave, Dieter Menne, Liviu Andronic

#
Please, do not write "Help, Help" but give a meaningful header. Most people
here a specialized and check the posts they understand best.
Madhavi Bhave wrote:
It's fine that you posted the working part; in general, for posting you
should simplify the thing that do work to the bare bones (see example below)
Madhavi Bhave wrote:
The most elegant approach uses package plyr; you even get the function
parameters in your output.

library(plyr)
# simplified version of your original function
duration = function(par_value, coupon_rate) 
{
  data.frame(macaulay_duration=2*par_value,modified_duration=3*coupon_rate) 
}

# use read.table in your application instead of the line below
pars = data.frame(par_value=c(1000,100), coupon_rate=c(10,7))

mdply(pars,.fun=duration)
#  par_value coupon_rate macaulay_duration modified_duration
#1      1000          10              2000                30
#2
#
Hello
On Wed, Jan 20, 2010 at 7:00 AM, Madhavi Bhave <madhavi_bhave at yahoo.com> wrote:
I am not sure that this would be the most efficient, but see if
something similar does the job for you:
x <- matrix(NA, 5,2); x
for (i in 1:5){
    x1 <- cbind(mean(rnorm(100)), mean(runif(100)))  ## use duration()
instead of cbind() and r*() funs
    x[i, ] <- x1
}
x

Liviu