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
8
votes
1 answer

How do I vertically join or merge multiple datasets within R

I have 12 datasets that all resemble this (this is a sample, the real datasets all contain over 10,000 varying rows, with the same number/name of columns) df1 Start End Duration 9/10/2019 1:00:00 PM …
Lynn
  • 4,292
  • 5
  • 21
  • 44
8
votes
2 answers

rbind data frames based on a common pattern in data frame name

Say I have multiple data frames which all have identical vector names and I'd like to cbind all which have a commmon pattern. So for these 3 data frames: df.1 <- data.frame(column1 = factor(sample(c("Male","Female"), 10, replace=TRUE)), …
Jojo
  • 4,951
  • 7
  • 23
  • 27
8
votes
2 answers

How to merge multiple data.frames and sum and average columns at the same time in R

I have over 20 twenty data.frames with the same columns but differing amount of rows. My goal is to merge the data.frames by the column "Name" (which is a list of five names) and while merging I would like the rows with the same name to sum column…
Dre
  • 713
  • 1
  • 8
  • 27
8
votes
3 answers

R: Combine list of data frames into single data frame, add column with list index

The question is very similar to this one . It is for combining a list of data frames into a single longer data frame. However, I want to keep the information from which item of the list the data came from by adding an extra column with the index (id…
Jose R
  • 930
  • 1
  • 11
  • 22
8
votes
1 answer

Why does rbindlist not respect column names?

I just discovered this bug, only to find that some people are calling it a "feature". This makes rbindlist NOT like do.call("rbind",l) as rbind WILL respect column names. Further, there is no mention of this entirely unexpected behavior in the…
James
  • 630
  • 1
  • 6
  • 15
8
votes
1 answer

rbind data.frames without names

I am trying to figure out why the rbind function is not working as intended when joining data.frames without names. Here is my testing: test <- data.frame( id=rep(c("a","b"),each=3), time=rep(1:3,2), black=1:6, …
thelatemail
  • 91,185
  • 12
  • 128
  • 188
7
votes
2 answers

Concat list of pandas data frame, but ignoring column name

Sub-title: Dumb it down pandas, stop trying to be clever. I've a list (res) of single-column pandas data frames, each containing the same kind of numeric data, but each with a different column name. The row indices have no meaning. I want to put…
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
7
votes
2 answers

Mixed type in vector (rbind dataframe without typeconversion)

In R a vector can not contain different types. Everything must e.g. be an integer or everything must be character etc. This gives me headaches sometimes. E.g. when I want to add a margin to a data.frame, and need some coloumns to be numeric and…
Andreas
  • 6,612
  • 14
  • 59
  • 69
7
votes
1 answer

Split list every n elements and cbind, then rbind slices

I would like to slice every n elements of list, cbind the slice, and then rbind the slices. I can do this with the code below (n = 10 elements, list is 30 elements long). I 'manually' select every 10 elements of the list and then cbind these 10…
nofunsally
  • 2,051
  • 6
  • 35
  • 53
7
votes
2 answers

rbind tbl and df gives errors with filter

I am using dplyr and loving it, but found a strange behavior. I am cleaning some data from different sources and putting them together in a data frame. Part of it required more cleaning, done with dplyr and resulted in a tbl object. The other part…
JG11235
  • 563
  • 3
  • 11
7
votes
1 answer

do.call rbind of data.table depends on location of NA

Consider this do.call(rbind, list(data.table(x=1, b='x'),data.table(x=1, b=NA))) returns x b 1: 1 x 2: 1 NA but do.call(rbind, list(data.table(x=1, b=NA),data.table(x=1, b='x'))) returns x b 1: 1 NA 2: 1 NA How can i force the first…
Sapsi
  • 711
  • 5
  • 16
7
votes
4 answers

interweave two data.frames in R

I would like to interweave two data.frame in R. For example: a = data.frame(x=1:5, y=5:1) b = data.frame(x=2:6, y=4:0) I would like the result to look like: > x y 1 5 2 4 2 4 3 3 3 3 ... obtained by cbinding x[1] with y[1], x[2] with…
Alex
  • 19,533
  • 37
  • 126
  • 195
6
votes
2 answers

Appending the row to data.table works differently than in data.frame: How and why?

Why does the following code not work? library(data.table) team_table <- as.data.table(matrix(NA,ncol = 11)) rbind(team_table,1:11) While the same version with data.frame does? team_table <-as.data.frame(matrix(NA,ncol = 11)) rbind(team_table,1:11)
Djpengo
  • 379
  • 2
  • 14
6
votes
1 answer

After doing bind_rows() and rbind() on same data.tables , identical() = FALSE?

Caveat: novice. I have several data.tables with millions of rows each, variables are mostly dates and factors. I was using rbindlist() to combine them because. Yesterday, after breaking up the tables into smaller pieces vertically (instead of the…
armipunk
  • 458
  • 2
  • 13
6
votes
1 answer

R: Error in pi[[j]] : subscript out of bounds -- rbind on a list of dataframes

I am trying to rbind a large list of data frames (outputDfList), which is generated by lapply a complicated function to a large table. You can recreate outputDfList by: df1=data.frame("randomseq_chr15q22.1_translocationOrInsertion", "chr15",…
Helene
  • 953
  • 3
  • 12
  • 22
1 2
3
60 61