[R] multiple versions of function

David Winsemius dwinsemius at comcast.net
Tue Jan 8 17:00:08 CET 2013


On Jan 7, 2013, at 6:58 PM, ivo welch wrote:

> hi david---can you give just a little more of an example?  the
> function should work with call by order, call by name, and data frame
> whose columns are the names.  /iaw
>

It is I who should be expecting you to provide an example.

--  
David.
>
> ----
> Ivo Welch (ivo.welch at gmail.com)
>
>
> On Mon, Jan 7, 2013 at 4:25 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>>
>> On Jan 7, 2013, at 3:57 PM, ivo welch wrote:
>>
>>> dear R experts:
>>>
>>> I want to define a function the calculates the black-scholes value.
>>> it takes 5 named parameters, BS <- function(S,K,dt,rf,sigma) {} .
>>> let's presume I want to be able to call this not only with my 5
>>> numeric vectors BS( sigma=0.3, S=100, K=100, dt=1, rf=0.1 ) and BS(
>>> 100, 100, 1, 0.1, 0.3), but also with a data frame that contains the
>>> variables alll in a neat data frame already, BS( data.frame( S=100,
>>> K=100, dt=1, rf=0.1, sigma=0.3 )).  I could of course define BS6 and
>>> BS1, but it would be nice to wrap this functionality into one  
>>> function
>>> that can do both.
>>>
>>> I know that BS has to parse an '...' argument, but there could be a
>>> couple of magical R functions that might make this easier than I  
>>> would
>>> do it with my planned clunky version.     what's the elegant  
>>> version?
>>>
>>
>> apply( dfrm, 1, BS)
>>
>> --
>>
>> David Winsemius
>> Alameda, CA, USA
>>

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list