8 ms·
R: the good parts
- urlwolf 13y agoThere are people who think that there's elegance in R's design. Remember that is as old as C (if not more!), but it still feels like a modern language (warts and all). You don't compare C to say clojure for language features, they show the advances in language design over the years. R says: 'everything is a vector, and vectors can have missing values'. This is profound. It was only recently that other matrix-oriented language extensions (say panda) got missing values, even though they are meat-and-potatoes for data analysis.
- jzwinck 13y agoMost folks use IEEE floats as their value type, so in a way a whole lot of libraries have supported missing values for a long time. Many languages can use 32- and 64-bit floats; R can only use one or the other (you have to rebuild it to change this). This can make your big data twice as big as it should be. In that, R is in the company of such serious number-crunching languages as Lua, JavaScript, and Splunk.
- bokchoi 13y agoSAS has missing values as well and goes further -- there are multiple types of missing values (ie, "not available", "doesn't pass quality control review", etc.) We added missing values to our product to interop with both R and SAS: https://www.labkey.org/wiki/home/LabKey%20Server%20Documentation/page.view?name=manageMissing https://www.labkey.org/wiki/home/LabKey%20Server%20Documenta... (Pardon the extremely old screenshots.)
- hadley 13y agoIn SAS, beware that missing values are treated as the smallest possible value (e.g. -Inf). This means that statements like x < 10 return true if x is missing.
- lsiebert 13y agoOh god yes, and it will bite you if you don't know it. That takes me back to cleaning SAS data.
- pitnips 13y agoBut R is free!
- mwexler 13y agoWell, it's not older than C, but around the same time. Wikipedia shows S (R's commercial inspiration, for want of a better term) was first written in 1976, but C was around back in 1972. And C was adopted by lots of people a lot faster than S, though it kept chugging along. Agree with the missing values in native datatypes point, although many libraries for other languages had workarounds for missing values that allowed you to get similar results even back in the day, way before python and panda. I think the general consensus is that for every thing S and R got right, they got a bunch of other stuff not-so-right, but it was worth the pain to work around them because the good stuff was so very good.
- withme 13y agoRegarding the adoption rate of S, I think you hit upon a key source of the complaints about R. R existed in one form or another for a (relatively) small, specialized audience for a long, long time. This included the period where transitioning from S to R included placing a very high priority on maintaining code from S, even being able to replicate the bugs from S. This made a lot of sense from the perspective of a (relatively) small group of statisticians making a data analysis language for their own uses. Over the last 10 years, R has become massively more popular, and many, many more people are using it outside of its "base" audience. Not surprisingly, many of these new users are discovering that R was not designed with their personal use cases in mind. Given these constraints, R has done a remarkably good job of adjusting (where it can) to accommodate the diversification in its user base. But you can only go so far without just re-writing it from scratch, and the interests of R Core will always bend towards themselves and their, well, "core" audience.
- minimaxir 13y agoI hadn't used data.table or plyr because the native R functions were giving me good performance even at tens of thousands of rows. But now that I'm doing analysis on hundreds of thousands of rows, doing aggregation takes awhile. This article convinced me to give those packages a try. If data.table and plyr aggregate functions are indeed paralellizeable, that's a big deal, especially when implementing bootstrap resampling.
- jasonpbecker 13y agoYou should know that dplyr, plyr's replacement is already fairly stable and worth using. For basic tasks, it's as fast or faster than data.table in my experience, with the caveat that it is more likely to copy for some methods than data.table which is very strict about this.
- minimaxir 13y agoWow, if the benchmarks are true, then dplyr sounds perfect. http://blog.rstudio.org/2014/01/17/introducing-dplyr/ http://blog.rstudio.org/2014/01/17/introducing-dplyr/
- peatmoss 13y agoAnd being able to combine it with an RDBMS means that you can potentially do plyr-ish things on datasets that can't fit in memory. I think the SQL generated by dplyr tries to be smart / efficient too.
- chubot 13y agoI use data.table and like it. It's fast (and I think memory efficient). plyr is IMO so slow to be unusable on just hundreds of thousands rows. dplyr, as mentioned, is the replacement that fixes it, but it was literally first released a couple months ago this year. I have no doubt Hadley will produce something brilliant, but I'm guessing it will undergo a lot of change to get there.
- kachnuv_ocasek 13y agoDoes anyone else have issues viewing the page in Chrome 33? This is what I see: http://puu.sh/7ZAfb.png http://puu.sh/7ZAfb.png
- urlwolf 13y agoWOw! sorry about that! could you give more details about your setup? I tested it under chromium 31, and chrome canary 36.0. Anything helps.
- Fomite 13y agoWhile I'm not as fond of ggplot2 as the author is, and actually prefer base graphics when making things for publication, I think he hits on a lot of strong points. I'm rather fond of R as a language, and hop between it and Python as my preferred tools of choice for a given task. I think the package ecosystem is it's biggest plus - for statistical work, Python might have a package to do something, R almost certainly will.
- bertil 13y agoI think the opinion of ggplot2 is unanimous: you can do so much more with it — but Lord Almighty, what an expense of time it is to do anything specific! People like it or not depending on how they value their free time. I always check in details with newbies what they are trying to do before I mention that name (it used to be surprisingly hard to come across it randomly) because once I have, it’s a rabbit hole -- and they generally have weird ideas, that need more several single-dimension graphs, easily done with hist() and plot(); however, anything a little subtle benefits so much from that flexibility. I still don’t understand why bucketed log-scale for histogram and properly typed percentage scales (i.e. “10%” and not “0.1”) are so hard to do, but I love impressing the one guy who tried by showing those casually.
- bosie 13y agoisn't it simply scale_y_log10(labels=percent_format())?
- bertil 13y agoThat’s one case, that doesn’t work well with user-defined buckets, has an unexplainable tendency to shift to ‘10.00%‘ when there is no room to do so and works with only certain of ggplot many wonderful graphs… But yes, that one, when it works is generally great.
- hadley 13y agoIt should work with any plot that has a y range greater than 0. ggplot2 can't do anything to fix the fact that log(x) for x <= 0 is undefined.
- baldfat 13y agoI still think that R has more users then Python with Pandas BUT the perception is that Pandas is bigger and better. I started with Pandas and learned R. I find that R is just better and if R isn't right then Julia or Closure will do the work. The tools in R are just better and more varied.
- jimmar 13y agoI've done some social science statistical analysis in R. I tried to reproduce the analysis using Python over the weekend, but the tools just aren't there. For example, doing a within-subjects ANOVA in R is maybe 3 lines of code. No native functions exist to do it in Python. Structural equation modelling? It doesn't exist in Python. I'm fairly sure that going forward, people will implement common social science statistical procedures in Python, but I need them today.
- baldfat 13y agoI just don't know if Python will actually be better after the tools are there. What R does is good what python will eventually be is good but not necessarily better.
- peatmoss 13y agoI think Python may be closer to ready if you're doing Bayesian stats. Going through some quantitative coursework for a phd in a social science, my experience has been that for frequentist stats, R has everything and Python has a tiny fraction. On the other hand, I'm taking a Bayesian course now, and am thinking that I could probably do the whole works in Python with little effort. That said, I'm not sure doing things in Python would actually buy me anything over R. If I were to do something other than R it would probably be something like Julia or Clojure, but that would also be more for my amusement rather than for any practical reason.
- bernardom 13y agoDoes anyone know of a good explanation of how plyr, dplyr, data.table and *apply functions differ? I'd love to read an in-depth analysis of each and make an informed decision on which one to use going forward. My current m.o. is to use data.frames as needed and plyr if I need to do any serious manipulation (which means that every time I use plyr, I need to read the docs). There's a lot of benefit to picking one direction and sticking with it...
- disgruntledphd2 13y agoData table is the fastest and most performant for many core data frame operations. plyr is wonderful for complex manipulations, but really slow as you start aggregating by a column with many (1000+) distinct values. The base functions are super-fast (they're written in C), but give you output that you need to manipulate into more useful formats. Additionally, there's some frustrating subtle differences in syntax between them that makes for some annoyances.
- washedup 13y agoHere is a summary of the apply family of functions: http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/ http://nsaunders.wordpress.com/2010/08/20/a-brief-introducti... These are very simple functions and I generally try to use them before moving on to plyr. The are easy to set up, understand, and faster. Obviously they cannot do everything, though, which is why there is plyr.
- yrochat 13y agoHere is for the *apply functions: http://stackoverflow.com/questions/3505701/r-grouping-functions-sapply-vs-lapply-vs-apply-vs-tapply-vs-by-vs-aggrega http://stackoverflow.com/questions/3505701/r-grouping-functi... That's the option I use, daily.
- craigching 13y agoI just discovered that link when the article was posted at datatau. That is definitely the best explanation I've found for apply.
- Malarkey73 13y agoI agree with most of what they say here - except using data.table. I much prefer using data.table structures with dplyr a far simpler more familiar syntax. Indeed data.table - the object implementation - is brilliant and should just replace data.frame ...if that were possible.
- oddthink 13y agoThe real problem with data.table is that it has too much magic. It's great for interactive use, but it's hard to program to. If, for example, you want to aggregate a table using a list of supplied variable names, like if you wanted to abstract out some aggregation code, you need to descend into horrible quote/substitute/etc. hackery to make it work.
- x0x0 13y agoI love R, and I think that the insight people often overlook for R's success is pretty simple: the easy things are easy. Doing hard things in R can be very hard, but the easy things are easy. Eg loading a csv full of data and running a regression on it are two lines of code that are pretty easy to explain to people: $ R data <- read.csv(file='some_file', header=T, sep=',') model <- lm(Y ~ COL1 + COL2 + COL3, data=data) and if you want to use glm -- logistic regression, etc -- it's a trivial change: model <- glm(Y ~ COL1 + COL2 + COL3, family=binomial, data=data) It really allows people to do quite powerful statistical analyses very simply. Note that they built a dsl for specifying regression equations -- and you don't have to bother with bullshit like quoting column column names; quoting requirements are often hard to explain to new computer users. R's other key feature is it includes a full sql-like data manipulation language to manipulate tabular data; it's so good that every other language that does stats copied it. If df is a dataframe, I can issue predicates on the rows before the comma and columns after the comma, eg df[ df$col1 < 3 & df$col2 > 7, 'col4'] that takes my dataframe and subsets it so -- row predicates before the comma -- col1 is less than 3 and col2 is greater than 7 -- and column predicates after the comma -- just returns a new dataframe from the subset with col4 in it. It's incredibly powerful and fast.
- beejiu 13y agoI wouldn't necessarily consider the 'bracket notation' a query, and it's very un-SQL like. It's simply three vector operations which returns a boolean vector e.g. (TRUE, FALSE, TRUE, ...), which is then used to select particular indices. I think this way of operating is more familiar to statisticians.
- Myrmornis 13y agoYes it's completely unlike SQL. Rather than declaring what is wanted and being agnostic about implementation, it actually specifies the implementation of the query, and does so using data structures of length equal to the dimension of the full table, so it's completely unscalable.
- showerst 13y agoI think of this as the statistics version of PHP's <? $paragraph = 'hello world'; echo '<p>'.$paragraph.'</p>'; ?> It makes a basic tasks super easy, which allows people who don't know what they're doing to make mistakes. It's just a different philosophy that has some negatives.
- JasonCEC 13y agoMy startups [1] does flavor profiling and statistical quality control for beer and bourbon producers - it's a fun job! Our entire back-end is built in R, mostly within the Hadly-verse, and we use Shiny [2] as our web framework. Our team works a bit differently than most, I suspect; our data-scientists build features and analysis directly in R, and then add the functionality to our Shiny Platform. Our "real devs" are all server + DB, or Android guys. This has created a great development system where all of the "cool findings" and 'awesome visualizations' are immediately implemented in our system, and made available for our clients! [1] www.Gastrograph.com [2] http://shiny.rstudio.com/ http://shiny.rstudio.com/ ---- EDIT --- Edited to add; R is a great language and is 100% suitable for production systems. Its older than Python(!), and, with some experience, can be made in to high performance code.
- urlwolf 13y agoAgreed, I've seen production R code, and it just works. Rstudio does some seriously good debugging tooling, and the testing frameworks are there. I do hear people calling R a toy language, but they are the ones that don't know much about it.
- reyan 13y agoHow do you deal with interoperability? You Android clients use your Shiny frontend over HTTP? Have you used rserve?
- JasonCEC 13y agoAll of our API's are built in R using rserve, and we share code and functions through an internal package hosted on bitbucket. You can call R functions on a server from Android and return the results in a list or array - makes for some really cool internal API magic between our devs and data-scientists :)
- sveme 13y agoGreat intro, just a minor nitpick to not spread confusion: Julia does actually have named arguments: http://docs.julialang.org/en/latest/manual/functions/#keyword-arguments http://docs.julialang.org/en/latest/manual/functions/#keywor...
- Myrmornis 13y agoRandom R gripe: it's hard to reuse code cleanly, because it lacks a nice import system like python, haskell, etc. Related: making a package is complicated (or was last time I looked).