Written and maintained by CASRAI Editorial Board
Published
On this page
rbind in R combines vectors, matrices or data frames by stacking them as rows, so the second object’s rows appear underneath the first’s. For data frames, base R’s rbind() matches columns by name rather than by position, and dplyr’s bind_rows() does the same while also filling any column missing from an input with NA. The rest of this page shows both functions on a research-style example, explains what each argument does, and separates stacking rows from adding columns (cbind) or matching records by key (a join).
What rbind is used for in research
Research data rarely arrive in one file. A study may export one table per collection wave, per site, per instrument run or per analyst, and every table has the same variables. Stacking those tables into one data frame is the job rbind() does: each input contributes rows, and the variables stay the same. This is different from cbind(), which adds columns to existing rows (see cbind in R), and different from a join, which pairs rows from two tables using a shared key (see joining data in R).
Both functions take any number of inputs in .... The base R manual page for cbind and rbind describes the arguments as “(generalized) vectors or matrices”, and the data frame method is the one called when the inputs are data frames. If you are new to the structure being stacked, data frames in R explains rows, columns and column classes first.
Worked scenario: stacking waves of a survey
The scenario below is an illustrative composite, not a real study. Suppose a research team holds three data frames, wave1, wave2 and wave3, each with the columns id, score and site, containing 40, 38 and 35 respondents. A stacked data frame should therefore have 113 rows and the same three columns. If wave 3 added a new column called mode, the base R manual only says that columns are matched by name, whereas the bind_rows() documentation states that missing columns are filled with NA, so bind_rows() is the documented route for that case. Because a research record needs to say which wave each row came from, the next sections show how to keep that provenance with the .id argument.
How to install or access rbind
rbind() is part of base R, so it is available as soon as R is installed, with no package to load. Download R from the Comprehensive R Archive Network (CRAN): the Windows download page carries the Windows installer, and the main CRAN site links the macOS and Linux downloads. RStudio is a separate editor that runs on top of R; how to use RStudio covers it.
bind_rows() belongs to the dplyr package, which is installed once and then loaded in each session. The dplyr home page gives these two commands:
install.packages("dplyr")installs only dplyr (install.packages("tidyverse")installs the whole tidyverse).library(dplyr)makes its functions available in the current session.
The dplyr site describes the package as “a grammar of data manipulation, providing a consistent set of verbs”. Background on the other verbs is in the dplyr package in R.
How to combine data frames by rows with rbind step by step
- Check that the column names agree. Run
names(wave1)andnames(wave2)and compare. The data frame method of rbind() matches columns by name, so the names must be the ones you intend to stack. - Stack with base R. Call
all_waves = rbind(wave1, wave2, wave3). The usage documented in the R manual for the data frame method isrbind(..., deparse.level = 1, make.row.names = TRUE, stringsAsFactors = FALSE, factor.exclude = TRUE). The result has the rows of wave1, then wave2, then wave3 (113 rows in the composite scenario). - Or stack with dplyr. After
library(dplyr), callbind_rows(wave1, wave2, wave3). The dplyr page documents the usage asbind_rows(..., .id = NULL)and accepts individual data frames, a list that could be a data frame, or a list of data frames. - Record provenance with .id. Put the frames in a named list and name the identifier column:
bind_rows(list(w1 = wave1, w2 = wave2, w3 = wave3), .id = "wave"). The documentation says that .id creates a new column linking each row to its original data frame, using the list names, or positions when the list is unnamed. The dplyr examples show this withbind_rows(list(a = df1, b = df2), .id = "id"), which produces anidcolumn holdingaandb. - Check the dimensions. Run
nrow(all_waves)and compare it with the sum of the inputs’ row counts. If they differ, an input was empty or was dropped (see troubleshooting below).
Stacking vectors and matrices
The same rbind() call stacks vectors or matrices into a matrix, one input per row. The manual’s examples use rbind(1:4, c = 2, "a++" = 10, dd, deparse.level = 0), where dd is 10. The argument deparse.level controls how row labels are built for non-matrix arguments: 0 builds no labels, 1 (the default) builds labels from argument names and deparses an expression only when it is a symbol, and 2 always builds labels. The manual’s comments on the three versions of that example say they produce 2, 3 and 4 row names respectively.
How to read the output
The object you get back depends on the inputs. With data frames, rbind() returns a data frame whose column classes come from the first data frame, and bind_rows() returns, in the dplyr documentation’s words, “a data frame the same type as the first element of …”. Put the data frame whose structure you want as the reference first, and a tibble first if you want a tibble back.
Row names
With make.row.names = TRUE, the default, rbind() builds unique, valid row names from the arguments. The manual’s own example builds data frames df and new and asserts that rbind(df, new) is identical to rbind(df, new, make.row.names = FALSE), so the argument is mainly relevant when the inputs carry their own row names. If you do not use row names for anything, treat the row index as a position, not an identifier, and keep real identifiers (a participant ID) in a column.
Missing columns and NA
The dplyr documentation example makes the NA behaviour concrete. With df1 = tibble(x = 1:2, y = letters[1:2]) and df2 = tibble(x = 4:5, z = 1:2), bind_rows(df1, df2) returns a tibble with 4 rows and 3 columns (x, y, z). The y values for the last two rows are NA, and the z values for the first two rows are NA. The result contains every column that occurs in any input, which is why the row count is the sum of the inputs and the column count is the union of the column names.
Factor columns
For factor columns, the base R manual states that factor levels are expanded as needed and that the result is an ordered factor only if all components were ordered factors. The factor.exclude argument defaults to TRUE, which keeps NA levels of factors. The stringsAsFactors argument, default FALSE, only has an effect when ... contains a non-data-frame character argument.
The data table below lists each documented argument of the two functions with its default, so the choices described in this section can be checked against the official pages.
Troubleshooting rbind
Binding rows when you wanted columns
rbind() stacks, cbind() sets side by side. If two tables describe the same people with different variables, the right move is usually a join on an ID, not rbind(). See joining data in R; the answer to “how to join two data sets in R” depends on whether the tables share variables (rbind or bind_rows) or share keys (a join).
The row count is lower than expected
The base R manual states that, for the data frame method, zero-column and zero-row arguments are dropped first. If none are left, the first argument is returned if it has columns, otherwise a zero-column zero-row data frame. An input that read in as zero rows therefore contributes nothing, so compare the inputs’ nrow() values before stacking.
The column classes look wrong after stacking
For the data frame method, the manual says the column classes are taken from the first data frame. If the first input read a column as one class and a later input read it as another, reorder the inputs or convert the column in each input before binding. The dplyr page for bind_rows() does not state how conflicting column types are resolved, so check the class of each column with str() on the result rather than assuming a rule.
Columns that exist in only some inputs
Use bind_rows() when inputs have different sets of columns and you want the union, with NA where a column is absent. The dplyr documentation states this behaviour explicitly. The base R manual states that the data frame method of rbind() matches columns by name; compare names first, as in step 1.
Many files, one stack
A list of data frames can be passed to bind_rows() directly, per its documentation, which avoids typing each name. A named list combined with .id gives you a provenance column in one call. For reading the files themselves, subsetting in R helps when you only need some rows or columns from each input before stacking.
Free alternatives to rbind
The table sets the two stacking functions beside the neighbouring operations that are often confused with them.
| Task | Function | What the official documentation says |
|---|---|---|
| Stack data frames, base R | rbind() | Data frame method matches columns by name; classes come from the first data frame; zero-row and zero-column arguments dropped first. |
| Stack data frames, dplyr | dplyr::bind_rows() | Columns matched by name; missing columns filled with NA; optional .id column records the source input; returns the type of the first input. |
| Add columns to the same rows | cbind() | Documented on the same base R manual page as rbind(); covered in cbind in R. |
| Match rows by a shared key | A join | A different operation from stacking; covered in joining data in R. |
Frequently asked questions
What is rbind in R programming?
rbind() is a base R function that combines its arguments by rows. The R manual documents it on the same page as cbind(), with the usage rbind(..., deparse.level = 1) and a data frame method that adds make.row.names, stringsAsFactors and factor.exclude. Each argument becomes one or more rows of the result.
What is rbind r?
It is the same function searched without the word “in”: rbind() in R, used to stack vectors, matrices or data frames by rows. The step-by-step section above shows the data frame version.
How to join two data sets in R?
It depends on what “join” means. If the two data sets have the same columns and you want more rows, stack them with rbind() or bind_rows(). If they describe the same records with different columns, match them on a shared key with a join, which joining data in R explains.
What does dplyr :: do in R?
The :: operator accesses an exported object in a package’s namespace, written pkg::name. The R manual states that it loads the namespace if needed but does not attach the package to the search path. That is why dplyr::bind_rows(df1, df2) works without calling library(dplyr) first.
What does n do in R?
Inside an R string, n is the escape sequence for a newline (the R manual’s quotes page lists it as “newline (aka ‘line feed’)”). It is unrelated to rbind(), but it shows up in output when strings are printed: the manual’s examples contrast print(), which displays the string in its input-like form, with writeLines(), which produces the actual line break.
Does rbind change the original data frames?
No assignment happens unless you make one. Write all_waves = rbind(wave1, wave2) to keep the stacked result under a name, and keep the originals so each wave can be checked against the stack.
Sources
- R Core Team, R documentation: Combine R Objects by Rows or Columns (cbind, rbind), checked 2026-11-19
- dplyr documentation: Bind multiple data frames by row (bind_rows), checked 2026-11-19
- dplyr documentation: A Grammar of Data Manipulation (installation), checked 2026-11-19
- R Core Team, R documentation: Double Colon and Triple Colon Operators, checked 2026-11-19
- R Core Team, R documentation: Quotes, checked 2026-11-19
- CRAN: Download R for Windows, checked 2026-11-19
Data: Documented arguments of base R rbind() and dplyr bind_rows()
Compiled from the base R manual page for cbind and rbind and the dplyr reference page for bind_rows. Each row lists one documented argument, the function it belongs to, its documented default and what the documentation says it does. No values are measured or estimated.
| Argument and function | Default | Documented effect |
|---|---|---|
| ... (rbind) | none | Inputs are (generalized) vectors or matrices; the data frame method is used for data frames. |
| deparse.level (rbind) | 1 | 0 constructs no labels; 1 constructs labels from argument names and deparses an expression only when it is a symbol; 2 always constructs labels. |
| make.row.names (rbind, data frame method) | TRUE | If TRUE, constructs unique, valid row names from the arguments. |
| stringsAsFactors (rbind, data frame method) | FALSE | Passed to as.data.frame; only has an effect when the inputs contain a non-data-frame character argument. |
| factor.exclude (rbind, data frame method) | TRUE | TRUE keeps NA levels of factors; otherwise used as the exclude value when factoring result columns. |
| ... (bind_rows) | none | Data frames to combine: a data frame, a list that could be a data frame, or a list of data frames. Columns are matched by name; missing columns are filled with NA. |
| .id (bind_rows) | NULL | Optional name of an identifier column recording which input each row came from, using input names or positions. |
Sources
- R documentation: Combine R Objects by Rows or Columns (accessed 2026-11-19)
- dplyr documentation: Bind multiple data frames by row (accessed 2026-11-19)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







