You are on page 1of 10

R PROGRAMMING

MADE EASY
LIVE!

LINEAR
REGRESSION
COMBINING TABLES

YOUR EXCEL SKILLS WILL


UNLOCK ADVANCED ANALYTICS
R PROGRAMMING MADE EASY - LIVE

If you have Microsoft Excel skills, I can teach you how to use R programming to
analyze your business data.

Doesn't matter if you've never coded before. Your basic skills with Excel tables,
formulas, and pivot tables makes this possible.

I know. It's a bold statement.

Despite helping 1000s of professionals learn R programming over the years, I don't
expect you to take my word for it.

This document demonstrates how your knowledge of Excel's VLOOKUP function


makes it easy to learn how to combine tables of data using R.

I like to let my content do the talking.

If you like this style of teaching, I wanted to let you know that I'll be delivering hands-
on training with R programming on September 26th, 27th, and 28th.

See page 9 to learn more.

Enjoy the content!

-Dave

2
R PROGRAMMING MADE EASY - LIVE

Combining Tables in Excel


VLOOKUP

While not the only way to combine tables of data, Excel's VLOOKUP function is the
most common. From Microsoft's documentation:

"Use VLOOKUP when you need to find things in a table or a range by row."

Take the image below as an example.

LINEAR
REGRESSION
The Excel code above is using the values of Column E to match the values stored in
Column I.

Column E contains only the values of setosa, versicolor, and virginica. All cells in Column
E contains one of these values (i.e., no data is missing).

VLOOOKUP uses values from the left table to match on values in the right table.
Where' matches are found, the values from Column J are copied to Column F.

https://bit.ly/RProgrammingLiveTraining
3
R PROGRAMMING MADE EASY - LIVE

Continuing the example, if the <enter> key is pressed, the VLOOKUP function is
executed with the following results in the left table.

This is a classic example of using VLOOKUP. Let's consider a different case.

In the above case, the right table does not contain all the values that exist in Column E
of the left table.

When VLOOKUP cannot find a match in the right table, it returns #N/A which means
"no value available."

Notice how all rows from the left table are preserved.

https://bit.ly/RProgrammingLiveTraining
4
R PROGRAMMING MADE EASY - LIVE

Terminology

When using your knowledge of VLOOKUP to learn combining tables of data using R,
we need to establish some terminology. You've already been exposed to left table
and right table.

left table right table

Next is the join condition between two columns as illustrated below.

join condition

Combining tables in this way is called a left join.

https://bit.ly/RProgrammingLiveTraining
5
R PROGRAMMING MADE EASY - LIVE

Combining Tables in R
dplyr

The most common way to combine tables of data in R programming is to use the
mighty dplyr library.

Among the many functions provided by dplyr is the left_join function. Conceptually,
the left_join function does the same thing as VLOOKUP.

Consider the following two tables in R.

These tables have the same data as in the Excel example and will be used in learning
how to perform left joins using dplyr.

In this example, iris_data will be the left table and iris_stats will be the right table.

https://bit.ly/RProgrammingLiveTraining
6
R PROGRAMMING MADE EASY - LIVE

R Code

As mentioned on the previous page, the left_join function is used to combine tables
using left joins.

The following code comparison shows how your VLOOKUP knowledge maps to
using R code.

left table right table

=VLOOKUP(E2, $I$3:$J$5, 2, FALSE)

LINEAR
join condition

REGRESSION
left table right table

left_join(iris_data, iris_stats, by = "Species")

join condition

The process of mapping your Excel knowledge to R is a primary reason why R


programming is the quickest, easiest way to scale past Excel and unlock advanced
analytics.

https://bit.ly/RProgrammingLiveTraining
7
R PROGRAMMING MADE EASY - LIVE

The left_join function does not change the data stored in left table and right table.

Instead, left_join creates a new combined table. The following code illustrates how to
store the new table.

new_table <- left_join(iris_data, iris_stats, by = "Species")

We can use R to view the data stored in new_table.

This just one of many examples of how your Excel knowledge maps to R
programming.

Ready to scale past Excel and unlock advanced analytics like time series forecasting
and machine learning?

https://bit.ly/RProgrammingLiveTraining
8
R PROGRAMMING MADE EASY - LIVE

"Dave! You are incredible! Thank you so much for being such an attentive
instructor!" - Bruce Lam

Certificate of completion
9 hours of instruction
Hands-on labs
Limited to 20 students
PDFs of all slides/labs
All R code
1-on-1 help if needed
Recordings if you miss a
class

Day 1 Day 2 Day 3


Sept 26th Sept 27th Sept 28th

You will learn: You will learn: You will learn:


Similarities of Excel & R R stats functions The mighty dplyr
R objects (e.g., tables) The summary function Hands-on Lab #3
Math with vectors R table functions Data viz with ggplot2
Filtering R tables The aggregate function Hands-on Lab #4
Hands-on lab #1 Hands-on lab #2 Additional resources

Ready to unleash the power of R with your data? Learn more at the link below.

https://bit.ly/RProgrammingLiveTraining
9
R PROGRAMMING MADE EASY - LIVE

About the Author

My name is Dave Langer and I am the founder of Dave on


Data.

I'm a hands-on analytics professional, having used my skills


with Excel, SQL, and R to craft insights, advise leaders, and
shape company strategy.

I'm also a skilled educator, having trained 100s of working


professionals in a live classroom setting and 1000s more via
my online courses and tutorials.

In the past, I’ve held analytics leaderships roles at


Schedulicity, Data Science Dojo, and Microsoft.

Drop me an email if you have any questions:


dave@daveondata.com

https://bit.ly/RProgrammingLiveTraining
10

You might also like