On 08/09/2011 04:39 AM, Annabel wrote: > I am trying to convert a matlab code to R. > Most of the conversion statements are simple, but problem is with return. > > Since it's a recursive function it's a bit complicated. Anyway in matlab > we can have return statment like > > [price, notional] = functionname() > > and also for the same function... > > notional(1) = functionname() > > how to do this in R? i have tried using data frame but still getting errors! > Yes the functioname() function is recursive...but am guessing it shouldn't > matter.
In what way have you tried using data.frames? Without "commented, minimal, self-contained, reproducible code" we are left guessing why you are not succeeding. In stead of using a data.frame to return multiple arguments, I would use a list. A short trvial example: foo = function() { return(list(foo = "bar", spam = 1, ham = c(1,2,3,4))) } dum = foo() dum dum[[1]] dum[[2]] dum[[3]] cheers, Paul > also there is no "return" statement in MatLab.......so finding it a bit > confusing. > > ______________________________________________ > R-help@r-project.org 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. -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 ______________________________________________ R-help@r-project.org 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.