Questions tagged [rbind]

Take a sequence of vector, matrix or data-frame arguments and combine by rows

Description

Take a sequence of vector, matrix or data-frame arguments and combine by rows, respectively. These are generic functions with methods for other R classes.

rbind(..., deparse.level = 1)

S3 method for class 'data.frame'

rbind(..., deparse.level = 1, make.row.names = TRUE) Arguments

... (generalized) vectors or matrices. These can be given as named arguments. Other R objects may be coerced as appropriate, or S4 methods may be used: see sections ‘Details’ and ‘Value’. (For the "data.frame" method of cbind these can be further arguments to data.frame such as stringsAsFactors.)

deparse.level
integer controlling the construction of labels in the case of non-matrix-like arguments (for the default method): deparse.level = 0 constructs no labels; the default, deparse.level = 1 or 2 constructs labels from the argument names, see the ‘Value’ section below.

make.row.names
(only for data frame method:) logical indicating if unique and valid row.names should be constructed from the arguments.

Details

The functions cbind and rbind are S3 generic, with methods for data frames. The data frame method will be used if at least one argument is a data frame and the rest are vectors or matrices.

907 questions
151
votes
3 answers

Why is rbindlist "better" than rbind?

I am going through documentation of data.table and also noticed from some of the conversations over here on SO that rbindlist is supposed to be better than rbind. I would like to know why is rbindlist better than rbind and in which scenarios…
CHP
  • 16,981
  • 4
  • 38
  • 57
90
votes
10 answers

R: losing column names when adding rows to an empty data frame

I am just starting with R and encountered a strange behaviour: when inserting the first row in an empty data frame, the original column names get lost. example: a<-data.frame(one = numeric(0), two = numeric(0)) a #[1] one two #<0 rows> (or 0-length…
cdmihai
  • 3,008
  • 2
  • 20
  • 18
64
votes
2 answers

Difference between rbind() and bind_rows() in R

On the web, I found that rbind() is used to combine two data frames by rows, and the same task is performed by bind_rows() function from dplyr. What's the difference between these two functions, and which one is more efficient?
asad_hussain
  • 1,959
  • 1
  • 17
  • 27
56
votes
2 answers

Simplest way to get rbind to ignore column names

This came up just in an answer to another question here. When you rbind two data frames, it matches columns by name rather than index, which can lead to unexpected behavior: > df<-data.frame(x=1:2,y=3:4) > df x y 1 1 3 2 2 4 > rbind(df,df[,2:1]) …
mrip
  • 14,913
  • 4
  • 40
  • 58
46
votes
6 answers

Converting nested list to dataframe

The goal is to convert a nested list which sometimes contain missing records into a data frame. An example of the structure when there are missing records is: mylist <- list( list( Hit = "True", Project = "Blue", Year = "2011", …
Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56
34
votes
7 answers

How can I rbind vectors matching their column names?

rbind does not check for column names when binding together vectors: l = list(row1 = c(10, 20), row2 = c(20, 10)) names(l$row1) = c("A", "B") names(l$row2) = c("B", "A") l $row1 A B 10 20 $row2 B A 20 10 rbind(l$row1, l$row2) A …
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
33
votes
4 answers

Efficient way to rbind data.frames with different columns

I have a list of data frames with different sets of columns. I would like to combine them by rows into one data frame. I use plyr::rbind.fill to do that. I am looking for something that would do this more efficiently, but is similar to the answer…
mrkilinc
  • 333
  • 1
  • 3
  • 5
29
votes
4 answers

Memory efficient alternative to rbind - in-place rbind?

I need to rbind two large data frames. Right now I use df <- rbind(df, df.extension) but I (almost) instantly run out of memory. I guess its because df is held in the memory twice. I might see even bigger data frames in the future, so I need some…
Sebastian
  • 3,679
  • 3
  • 19
  • 14
27
votes
5 answers

rbind dataframes with a different column name

I've 12 data frames, each one contains 6 columns: 5 have the same name, 1 is different. Then when I call rbind() I get: Error in match.names(clabs, names(xi)) : names do not match previous names The column that differs is: "goal1Completions".…
Omar Gonzales
  • 3,806
  • 10
  • 56
  • 120
21
votes
1 answer

join two or more data frames in system R

My questions is how can join two or more data frames in system R? For example: I have two data frames: first: x y z 1 3 2 4 2 4 5 7 3 5 6 8 second: x y z 1 1 1 1 2 4 5 7 I need this: x y z 1 3 2 4 2 4 5 7 3 5 …
olga
  • 211
  • 1
  • 2
  • 4
20
votes
3 answers

Convert a list of sf objects into one sf

I have a list of sf objects that I would like to row bind to create a single sf object. I'm looking for a function similar to data.table::rbindlist, that would stack the individual objects in an efficient manner. Data for reproducible…
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
20
votes
6 answers

What's wrong with my function to load multiple .csv files into single dataframe in R using rbind?

I have written the following function to combine 300 .csv files. My directory name is "specdata". I have done the following steps for execution, x <- function(directory) { dir <- directory data_dir <- paste(getwd(),dir,sep = "/") …
Sivanantham C
  • 231
  • 1
  • 2
  • 8
19
votes
6 answers

how to determine if a character vector is a valid numeric or integer vector

I am trying to turn a nested list structure into a dataframe. The list looks similar to the following (it is serialized data from parsed JSON read in using the httr package). myList <- list(object1 = list(w=1, x=list(y=0.1, z="cat")), object2 =…
Andrew Barr
  • 3,589
  • 4
  • 18
  • 28
17
votes
3 answers

Dispatch of `rbind` and `cbind` for a `data.frame`

Background The dispatch mechanism of the R functions rbind() and cbind() is non-standard. I explored some possibilities of writing rbind.myclass() or cbind.myclass() functions when one of the arguments is a data.frame, but so far I do not have a…
Stef van Buuren
  • 348
  • 1
  • 10
16
votes
1 answer

R rbind dataframes returns a list

I have run into a problem and managed to solve it with a hack and I wish to understand the problem and hopefully get rid of the hack. I tried recreating the problem to no avail, so words will have to suffice here. I am trying to rbind two dataframes…
gmarais
  • 1,801
  • 4
  • 16
  • 32
1
2 3
60 61