[R] Functions ,Optim, & Dataframe

From: Michael Papenfus <mmpapenf_at_wisc.edu>
Date: Mon 31 Jul 2006 - 15:46:50 EST

I have defined the following function:

fr<-function(x) {

    sqrt(sum((plnorm(c(3,6),u,v)-c(.55,.85))^2)) }
which I then solve using optim

> y$par

[1] 1.0029771 0.7610545
This works fine.

Now I want to use these two steps on a dataframe:  mydat<-data.frame(d1=c(3,5),d2=c(6,10),p1=c(.55,.05),p2=c(.85,.35))
> mydat

  d1 d2 p1 p2
1 3 6 0.55 0.85
2 5 10 0.05 0.35

where for each row in mydat, I append the two parameter resulting from optim into mydat.
I want to do this for a larger dataset but thought I would start with a simple two row dataframe.

I have tried this with loops and the apply function, but seem to be getting nowhere.
Thanks for any input.

R-help@stat.math.ethz.ch 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. Received on Mon Jul 31 15:54:56 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 31 Jul 2006 - 18:17:16 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.