Live data from Hacker News

Why do we use R rather than Excel?

shkspr.mobi

111–120 of 266 posts

Re: Why do we use R rather than Excel?

#111
post #4

Big big reason: R doesn't alter data without being asked to, Excel does so, silently, sneakily. Anything important should not be done in Excel. https://www.theverge.com/2020/8/6/21355674/human-genes-renam... https://stackoverflow.com/questions/165042/stop-excel-from-a...

So if I have Zip codes with leading 0’s, use R?

If you have zip codes, don't store those in a numeric type (doesn't matter if it's Excel, R, or any other system)

Zip codes aren't numbers, they are strings that happen to contain only numeric characters

Re: Why do we use R rather than Excel?

#113
post #96

For non-programmers who do any kind of data processing, spreadsheet applications (Excel, Numbers, Google Sheets) are the closest thing to programming they have, and have a lot less overhead - just throw in the data, write a formula, you get results, no compilation or fidgeting with input and output and so on. The steps of an algorithm are reflected by cells that reference cells that reference cells. I've always thoug…

> it really is a superpower in many contexts. It's a trap because once you get comfortable in Excel you have a lot of resistance to try anything more productive than Excel. Seen that numerous times with people who work really fast with Excel yet end up very limited as to what they can actually deal with beyond simple problems.

Can confirm. When I started working in academia, we built very sophisticated Excel models. But every new project would ask form ever more sophisticated sheets and workarounds. Once the calculations took more than a few minutes, I moved on to macros. But at that point I realized that I am using Excel as nothing more than a data container. That finally pushed me to learn Python and I felt never more liberated. Whenever I supervise PhD students now, I push them hard to learn programming early on. I am pretty sure never has any one of them had regret for following my advice. It simply adds a few degrees of freedom to their work.

Re: Why do we use R rather than Excel?

#115
post #4

Big big reason: R doesn't alter data without being asked to, Excel does so, silently, sneakily. Anything important should not be done in Excel. https://www.theverge.com/2020/8/6/21355674/human-genes-renam... https://stackoverflow.com/questions/165042/stop-excel-from-a...

So if I have Zip codes with leading 0’s, use R?

WAIT. All these words on SO and here have been written because people don't know to change the column type from "General" to "Text"?

Re: Why do we use R rather than Excel?

#116

This week I got a bit more familiar with R while adding it as a scripting language for a data IDE I'm working on (it already supported other languages). It is a very hard language and community to get into! The documentation is very sparse. Library documentation is published as PDF (I guess?) and also very sparse. The default `print` behavior is pretty hard to understand. It's 1-indexed and it took me a while to real…

> I'm also curious to investigate how the aspects I'm critical of differ in Octave.

Personal opinion, but happy to oblige.

> It is a very hard language and community to get into!

Same. Especially where "Matlab isn't Octave; Octave isn't Matlab" is concerned. Having said that, on stackoverflow at least, the matlab community seems more hostile to octave questions than the other way round.

> The documentation is very sparse.

Octave is actually fairly well documented, but unfortunately this is spread out significantly between manuals, helpstrings, and esoteric gems hidden as comments in the actual source code. However, this tends to be less of a problem, since often enough an equivalent function is documented in matlab, which is typically somewhat better in the documentation aspect. (octave is pretty good too though).

As for R, I think R is actually really well documented; you do kinda have to get used to its documentation format, but once you do there is nothing you'd want to do that you'll find yourself lacking documentation for.

(Proper R, that is. Tidyverse is a slightly different issue; but then again Tidyverse isn't R).

> Library documentation is published as PDF

You can have excellent in-terminal documentation using "?" and "??" (or "help" / "help.search" ). I have never needed to look at external manuals, but, yes, they do exist, typically in PDF form on CRAN. Furthermore, R is very good at accompanying documentation with examples / vignettes/ demos etc.

Octave, in theory, also does the same, but in practice I find many functions don't actually provide the demos. Typically they provide an in-doc example though.

> The default print behaviour is hard to understand.

Indeed. In fact, R seems to have some sort of infatuation with bash commands doing things in R-space, when in fact it would probably have been much more reasonable to leave the bash commands to do bash things. E.g. ls to list variables, rm to remove them, etc. And, yes, 'cat' to effectively print strings on the terminal verbatim, without other markings.

Octave is better here, bash-commands are generally identical within octave. 'print' is provided, but basically it's a wrapper to fprintf.

> It's 1-indexed.

Yes. Yes it is. This is not a bug, it's a feature. Same with octave, and same with julia. 0-indexing makes sense when you're working primarily with structures that depend on offsets (like pointers). 1-indexing is far more appropriate for languages that abstract such offset-based-structures away, and require ordinal, 'human-indexing' logic instead.

> it took me a while to realize every time I think `array[1]` I should write `array[[1]]`

Perhaps the chosen syntax is rather unfortunate, but Octave effectively uses the exact same logic here. If you have a cell array, you can either index it with () to obtain another cell array structure, OR you can index it with {} to obtain the 'contents' of that cell element.

> I can't tell the difference between `There are two main differences.

1. "can use it elsewhere, as long as it's toplevel, but you're discouraged from it.

2. Contrary to '=', the 'not evaluate rows(var) first, and then assign x to that.

> My guess is that it was probably a great language at some point but is way behind other numeric scripting languages like Julia or Matlab in terms of community attention and language ergonomics

False. Not sure what else to say about that. Once you start looking you'll be very surprised how active and cutting edge the R ecosystem is. It's just that language-preference seems very compartmentalised within different communities. R happens to be thriving in genomics / psychology crowds, whereas it's virtually unheard of in mainstream CS crowds.

> I know it's highly used but other than legacy reasons I'm not sure why you'd want to learn it over Julia.

Because, it has very interesting language designs. In fact, having effectively learned Julia first and R second, it became obvious to me that many of the aspects that I liked in Julia were effectively ideas taken from R. In fact, even though Julia is often compared to Matlab due to its superficially similar syntax, Julia is probably far more similar to R than matlab/octave.

Re: Why do we use R rather than Excel?

#117
post #70

For non-programmers who do any kind of data processing, spreadsheet applications (Excel, Numbers, Google Sheets) are the closest thing to programming they have, and have a lot less overhead - just throw in the data, write a formula, you get results, no compilation or fidgeting with input and output and so on. The steps of an algorithm are reflected by cells that reference cells that reference cells. I've always thoug…

I've always thought that every highschooler should be taught the basics of programming with an easy language like Python instead. That really is a superpower in a lot more contexts.

That's becoming more common in the US. My spouse teaches middle school STEM and programming is part of the curriculum, beginning with Scratch JR and working up to Python and JavaScript. It's not ubiquitous yet, but it's coming along.

Re: Why do we use R rather than Excel?

#118

IMO this really asks the question: Why is there not a code view for an excel spreadsheet? I get that some of the basic operations probably create expressions that are too wordy / very "specific data" intensive. That is, if you took the first step and just did your best to create that code view it would have a lot of stuff conditional on specific things. But it's the next step that gets interesting. Now that you've go…

I wrote a VBA function that returns the formula of a cell as a string, or "const" if the cell is not a formula, or "empty" if the cell is empty. (The latter is useful for finding bugs). Then I use it to display the formula in the cell immediately adjacent to where the formula actually resides. It's not a panacea, but overcomes the problem of "the code is invisible when reading a spreadsheet."

I don't remember the macro, it was more than a decade ago. Something along the lines of:

  function foo(c)
    s = c.Formula
    ' do something with s
    foo = s
Then in a cell, I could write something like:

  =foo(A32)

Re: Why do we use R rather than Excel?

#120
post #81
post #45

Earlier quoted context omitted.

"Floating-point arithmetic may give inaccurate results in Excel" https://docs.microsoft.com/en-us/office/troubleshoot/excel/f... "Align numerical precision Excel 2013 and R" https://stackoverflow.com/questions/39531655/align-numerical... "Numeric precision in Microsoft Excel" https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft...

Almost all of these are issues with floating point in general, I'd say. Some are with naive implementations of Excel functions, fair enough (for example variance as (sum x_i^2/n - (sum x_i/n)^2) that are indeed better implemented in R or Julia. IEEE 754 just has unintuitive properties. Kahan (the "father of IEEE 754") has a rant (among many others) about Excel as well, and how it tries to hide some of the floating po…

But you also have issues like 'Catastrophic cancellation':

https://carolomeetsbarolo.wordpress.com/2012/07/20/catastrop...

Or:

"OOPS XL Did It Again"

https://carolomeetsbarolo.wordpress.com/2014/06/22/oops-xl-d...

From the Wikipedia article:

"Although Excel can display 30 decimal places, its precision for a specified number is confined to 15 significant figures, and calculations may have an accuracy that is even less due to five issues: round off,truncation, and binary storage, accumulation of the deviations of the operands in calculations, and worst: cancellation at subtractions resp. 'Catastrophic cancellation' at subtraction of values with similar magnitude."

Post reply on HN