1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/bind.r 3\name{bind} 4\alias{bind} 5\alias{bind_rows} 6\alias{bind_cols} 7\title{Efficiently bind multiple data frames by row and column} 8\usage{ 9bind_rows(..., .id = NULL) 10 11bind_cols( 12 ..., 13 .name_repair = c("unique", "universal", "check_unique", "minimal") 14) 15} 16\arguments{ 17\item{...}{Data frames to combine. 18 19Each argument can either be a data frame, a list that could be a data 20frame, or a list of data frames. 21 22When row-binding, columns are matched by name, and any missing 23columns will be filled with NA. 24 25When column-binding, rows are matched by position, so all data 26frames must have the same number of rows. To match by value, not 27position, see \link{mutate-joins}.} 28 29\item{.id}{Data frame identifier. 30 31When \code{.id} is supplied, a new column of identifiers is 32created to link each row to its original data frame. The labels 33are taken from the named arguments to \code{bind_rows()}. When a 34list of data frames is supplied, the labels are taken from the 35names of the list. If no names are found a numeric sequence is 36used instead.} 37 38\item{.name_repair}{One of \code{"unique"}, \code{"universal"}, or 39\code{"check_unique"}. See \code{\link[vctrs:vec_as_names]{vctrs::vec_as_names()}} for the meaning of these 40options.} 41} 42\value{ 43\code{bind_rows()} and \code{bind_cols()} return the same type as 44the first input, either a data frame, \code{tbl_df}, or \code{grouped_df}. 45} 46\description{ 47This is an efficient implementation of the common pattern of 48\code{do.call(rbind, dfs)} or \code{do.call(cbind, dfs)} for binding many 49data frames into one. 50} 51\details{ 52The output of \code{bind_rows()} will contain a column if that column 53appears in any of the inputs. 54} 55\examples{ 56one <- starwars[1:4, ] 57two <- starwars[9:12, ] 58 59# You can supply data frames as arguments: 60bind_rows(one, two) 61 62# The contents of lists are spliced automatically: 63bind_rows(list(one, two)) 64bind_rows(split(starwars, starwars$homeworld)) 65bind_rows(list(one, two), list(two, one)) 66 67 68# In addition to data frames, you can supply vectors. In the rows 69# direction, the vectors represent rows and should have inner 70# names: 71bind_rows( 72 c(a = 1, b = 2), 73 c(a = 3, b = 4) 74) 75 76# You can mix vectors and data frames: 77bind_rows( 78 c(a = 1, b = 2), 79 tibble(a = 3:4, b = 5:6), 80 c(a = 7, b = 8) 81) 82 83 84# When you supply a column name with the `.id` argument, a new 85# column is created to link each row to its original data frame 86bind_rows(list(one, two), .id = "id") 87bind_rows(list(a = one, b = two), .id = "id") 88bind_rows("group 1" = one, "group 2" = two, .id = "groups") 89 90# Columns don't need to match when row-binding 91bind_rows(tibble(x = 1:3), tibble(y = 1:4)) 92\dontrun{ 93# Rows do need to match when column-binding 94bind_cols(tibble(x = 1:3), tibble(y = 1:2)) 95 96# even with 0 columns 97bind_cols(tibble(x = 1:3), tibble()) 98} 99 100bind_cols(one, two) 101bind_cols(list(one, two)) 102} 103