Tunga Kantarcı
2017-Apr-05 16:34 UTC
[R] Yield to maturity calculation - bndyield equivalent of MATLAB in R
Thanks a lot Marc, for informing that R is object oriented, implying that one should always try to vectorise the code (although I am not so clear why this should be the case) but also for all the references you provide.
Marc Schwartz
2017-Apr-05 17:28 UTC
[R] Yield to maturity calculation - bndyield equivalent of MATLAB in R
> On Apr 5, 2017, at 11:34 AM, Tunga Kantarc? <tungakantarci at gmail.com> wrote: > > Thanks a lot Marc, for informing that R is object oriented, implying > that one should always try to vectorise the code (although I am not so > clear why this should be the case) but also for all the references you > provide.Hi, The reason for taking an object oriented approach using vectorized code, is that frequently, the R code that you write is internally calling compiled C code to perform the actual iterations over the object structure. Thus, being that compiled C code is much faster than interpreted R code, there is significant efficiency to be achieved by taking an object oriented approach to key operations. In addition, when used, a single line of vectorized code and/or a vectorized function can replace multiple lines of code in a different language. Thus, from a coding efficiency and readability standpoint, it is far more efficient. Regards, Marc
Bert Gunter
2017-Apr-05 17:43 UTC
[R] Yield to maturity calculation - bndyield equivalent of MATLAB in R
... Probably need to distinguish "whole object approach" from "object oriented" approach. They are different and almost orthogonal in R. R tutorials discuss such matters, and there are many good ones on the Web, including the "Intro to R" tutorial that ships with R. The OP should spend some time with one or more to learn more about this. This list cannot provide such extended explanation. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Apr 5, 2017 at 10:28 AM, Marc Schwartz <marc_schwartz at me.com> wrote:> >> On Apr 5, 2017, at 11:34 AM, Tunga Kantarc? <tungakantarci at gmail.com> wrote: >> >> Thanks a lot Marc, for informing that R is object oriented, implying >> that one should always try to vectorise the code (although I am not so >> clear why this should be the case) but also for all the references you >> provide. > > > > Hi, > > The reason for taking an object oriented approach using vectorized code, is that frequently, the R code that you write is internally calling compiled C code to perform the actual iterations over the object structure. Thus, being that compiled C code is much faster than interpreted R code, there is significant efficiency to be achieved by taking an object oriented approach to key operations. > > In addition, when used, a single line of vectorized code and/or a vectorized function can replace multiple lines of code in a different language. Thus, from a coding efficiency and readability standpoint, it is far more efficient. > > Regards, > > Marc > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Tunga Kantarcı
2017-Apr-05 18:38 UTC
[R] Yield to maturity calculation - bndyield equivalent of MATLAB in R
OK this confused me. I thought object oriented coding should be preferred because it allows cleaner, more efficient coding. But your reply suggests it should be preferred because "R" is more efficient in that way. Anyhow, this thread should indeed not become a discussion point for this and I should read about it. On Wed, Apr 5, 2017 at 7:28 PM, Marc Schwartz <marc_schwartz at me.com> wrote:> >> On Apr 5, 2017, at 11:34 AM, Tunga Kantarc? <tungakantarci at gmail.com> wrote: >> >> Thanks a lot Marc, for informing that R is object oriented, implying >> that one should always try to vectorise the code (although I am not so >> clear why this should be the case) but also for all the references you >> provide. > > > > Hi, > > The reason for taking an object oriented approach using vectorized code, is that frequently, the R code that you write is internally calling compiled C code to perform the actual iterations over the object structure. Thus, being that compiled C code is much faster than interpreted R code, there is significant efficiency to be achieved by taking an object oriented approach to key operations. > > In addition, when used, a single line of vectorized code and/or a vectorized function can replace multiple lines of code in a different language. Thus, from a coding efficiency and readability standpoint, it is far more efficient. > > Regards, > > Marc >