4 ms·
A big problem with R is that it's just stats. The other day I wanted to do a simple loan amortization (simple PMT/IPMT in Excel). People say 'use R over Excel!'
by roel_v 10y ago
A big problem with R is that it's just stats. The other day I wanted to do a simple loan amortization (simple PMT/IPMT in Excel). People say 'use R over Excel!'. Right. There are some clunky barely-working packages in R that do half of what you need and some stack overflow posts that mostly show how to do the other half, but that's no basis to build on.
And don't get me started on string handling in R, or that there's no way to get the path of the currently running script, or a dozen other things that are trivial in a general purpose language but are a major pain in R. R is not 'general purpose' enough, and it doesn't have to be useful to write both kernel drivers and database REST frontends, but being able to do things that are math-related and not purely stats - that's not too much to ask for I'd say. Especially because it's not reasonable to ask people whose main job is not writing software to learn multiple languages/tools.
(Other recent example I remember: how unintuitive I found it to plot a sine wave and its first and second derivative. My Mathematica-oriented colleague did it in 2 minutes.)
- ldp01 10y agoThere are many things wrong with R but basic plotting functions are one of its strengths. Is this the way you did it? It seems pretty intuitive... a=pi/180 x=1:360 plot(x,sin(a * x)) plot(x,a * cos(a * x)) plot(x,-a^2 * sin(a * x))
- hadley 10y agoOr plot(sin) plot(D(sin)) (Programming from memory on my phone so might be slightly off)
- roel_v 10y agoBut that just draws 3 separate plots. My main problem was the derivative, not so much the plotting (or maybe it was 'plotting an arbitrary function'); but I looked it up and it seems I slightly misremembered what it was I wanted to do. I wanted to draw a cubic spline, not a sine. What I ended up doing was spline_x <- 1:6 spline_y <- c(0, 0.5, 2, 2, 0.5, 0) spl_fun <- splinefun(spline_x, spline_y) p <- ggplot(data.frame(x=spline_x, y=spline_y), aes(x, y)) p <- p + stat_function(fun = spl_fun) p <- p + stat_function(fun = spl_fun, arg = list(deriv = 2)) I still don't quite understand how that derivative works - ?list doesn't mention anything about 'deriv', and there's a function called 'deriv' but I'm not sure how that's being interpreted in the code above. Also it seems recent versions of ggplot2 have geom_xspline() which does what I need (I'm told) but that wasn't in the release version when I was doing it.
- hadley 10y agoIt took me 5 minutes to figure out how that actually did work! That is rather esoteric code! (FWIW the reason that there's no native support in ggplot2 for this sort of smoothing is that I think it's a really bad idea as it tends to distort the underlying data)
- larrydag 10y agoR is only recently getting involved in the financial world. Most of R development has been in academia focusing on biostatistics, clinical trials and such. There is an R in Finance conference every year. Also there are a lot of good packages for securities, investing, and risk management. https://cran.r-project.org/web/views/Finance.html https://cran.r-project.org/web/views/Finance.html