R Explained for Excel Users: Assigning Variables

The single-greatest difference?

R and Excel are both powerful tools for the analyst. A good analyst uses each when appropriate.

Many analysts haven’t used R, for different reasons. For one, it has a steeper learning curve than Excel. It is also less likely to be used by your boss.

But it is a very powerful tool. 

There are some real differences between the two. Perhaps the single-greatest is the assignment of variables in R.  

When writing a formula in Excel, we point-and-click on a cell to reference, and Excel will write the cell reference for us (e.g., cell A1, column B, range C1:D4, etc).

In R, we need to name everything we will reference. 

In the below example, I perform a simple function (summing 2, 1, and 6; Cleveland’s area code!) in both R and Excel.

07

Notice that in Excel I just drop each number into a cell, grab another cell, and sum them.

It’s not actually less than…

In R,  I assign these numbers to a vector, then sum. 

I do this with the symbol “<-“. This takes some getting used to; think of it as a reverse arrow pointing your expression to the variable. 

You can technically use “=” instead of “<-“. If this notation makes you more comfortable as an Excel user in the early days of learning R, go for it. But programmers nearly universally use the “<-” notation. 

Subscribe to my mailing list.

Leave a Reply

%d bloggers like this: