Combining and Reshaping Data
Explore merging, appending, and reshaping data sets for flexible analysis.
Combining and Reshaping Data is a free R Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the R Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Introduction to Combining and Reshaping Data
Data often comes from multiple sources and needs to be merged or reshaped for analysis. In this lesson, you will learn how to combine and restructure data in R.

2
Combining Data Frames
You can combine data frames using functions like rbind() (row-wise) and cbind() (column-wise).
df1 <- data.frame(ID = c(1, 2), Score = c(90, 85))
df2 <- data.frame(ID = c(3, 4), Score = c(78, 92))
df_combined <- rbind(df1, df2)3
Merging Data Frames
To merge two data frames by a common column, use merge().
df1 <- data.frame(ID = c(1, 2, 3), Name = c('Alice', 'Bob', 'Charlie'))
df2 <- data.frame(ID = c(1, 2, 3), Score = c(90, 85, 88))
merged_df <- merge(df1, df2, by = 'ID')4
Using dplyr for Joins
The dplyr package provides functions like left_join() and inner_join() for merging data.
library(dplyr)
joined_df <- left_join(df1, df2, by = 'ID')5
Pivoting Data with tidyr
Reshaping data is useful for summarizing and analyzing different formats.
6
Widening Data (pivot_wider)
Use pivot_wider() to convert long format data to wide format.
library(tidyr)
data_wide <- pivot_wider(df, names_from = Category, values_from = Value)7
Longer Data (pivot_longer)
Use pivot_longer() to convert wide format data to long format.
data_long <- pivot_longer(df, cols = c('Jan', 'Feb'), names_to = 'Month', values_to = 'Sales')8
9
Sorting Data
You can sort data frames using the arrange() function from dplyr.
df_sorted <- arrange(df, desc(Score))10
Summary
In this lesson, you learned:
- How to combine and merge data frames.
- How to reshape data using pivoting functions.
- How to sort and structure data efficiently.

Frequently asked questions
Is the “Combining and Reshaping Data” lesson free?
Yes — the full text of “Combining and Reshaping Data” is free to read here on the web, and the R Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the R Academy course, upgrade to CoddyKit PRO.
What will I learn in “Combining and Reshaping Data”?
Explore merging, appending, and reshaping data sets for flexible analysis. You practise R Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start R Academy?
No prior experience is required. R Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Combining and Reshaping Data” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this R Academy lesson?
Yes. Every R Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Importing Data
- Data Cleaning Basics
- Combining and Reshaping Data