Re: [R] How to vectorize this function

2018-09-20 Thread Lynette Chang
Here are the code and data file. I’m not sure if I put too much unrelated information here. My goal is to factor out volatilities from the data. I hope I can get sigV <- impVolC(callM, K, T, F, r), which has five vectors as input, and one vector as output. The length of all those six vectors a

Re: [R] How to vectorize this function

2018-09-20 Thread Jeff Newmiller
Sorry, misread your comment, I agree. 4/2 has one arithmetic operation, (1/2)*4 has two to accomplish the same calculation. On September 20, 2018 1:53:03 PM PDT, "MacQueen, Don" wrote: >You're asking me? > >I prefer >> 4/2 >[1] 2 > >not >> 1/2*4 >[1] 2 > >(I think that's what I said) > >And if

Re: [R] How to vectorize this function

2018-09-20 Thread MacQueen, Don via R-help
You're asking me? I prefer > 4/2 [1] 2 not > 1/2*4 [1] 2 (I think that's what I said) And if I did want to multiply by the reciprocal, which does happen from time to time, I'd certainly do it this way: (1/2)*4 -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-6

Re: [R] How to vectorize this function

2018-09-20 Thread Jeff Newmiller
re: your last comment... why do you prefer to multiply by the reciprocal? On September 20, 2018 10:56:22 AM PDT, "MacQueen, Don via R-help" wrote: >In addition to what the other said, if callM is a vector then an >expression of the form > if (callM <= call0) >is inappropriate. Objects inside t

Re: [R] How to vectorize this function

2018-09-20 Thread MacQueen, Don via R-help
In addition to what the other said, if callM is a vector then an expression of the form if (callM <= call0) is inappropriate. Objects inside the parentheses of if() should have length one. For example, > if (1:5 < 3) 'a' else 'b' [1] "a" Warning message: In if (1:5 < 3) "a" else "b" : th

Re: [R] How to vectorize this function

2018-09-20 Thread Bert Gunter
rom: R-help On Behalf Of Lynette Chang > Sent: Thursday, September 20, 2018 10:09 AM > To: r-help@r-project.org > Subject: [R] How to vectorize this function > > Hello everyone, > > I’ve a function with five input argument and one output number. > impVolC <

Re: [R] How to vectorize this function

2018-09-20 Thread David L Carlson
instead of the loop. David L Carlson Department of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of Lynette Chang Sent: Thursday, September 20, 2018 10:09 AM To: r-help@r-project.org Subject: [R] How to vector

[R] How to vectorize this function

2018-09-20 Thread Lynette Chang
Hello everyone, I’ve a function with five input argument and one output number. impVolC <- function(callM, K, T, F, r) I hope this function can take five vectors as input, then return one vector as output. My vectorization ran into problems with the nested if-else operation