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
15
votes
9 answers

How to append group row into dataframe

I have this df1: A B C 1 2 3 5 7 9 where A B C are columns names. I have another df2 with one column: A 1 2 3 4 I would like to append df2 for each column of df1, creating this final dataframe: A B C 1 2 3 5 7 9 1 1 1 2 2 2 3 3 3 4 4 4 is it…
giupardeb
  • 791
  • 1
  • 5
  • 13
14
votes
4 answers

Make rbindlist skip, ignore or change class attribute of the column

I would like to merge a large set of dataframes (about 30), which each have about 200 variables. These datasets are very much alike but not identical. Please find two example dataframes below: library(data.table) library(haven) df1 <- fread( "A …
Tom
  • 2,173
  • 1
  • 17
  • 44
14
votes
2 answers

rbind dataframes across nested lists

I've had a look at various rbinding list questions such as this but I can't really find a more efficient way of doing this. I have a nested list nestlist that contains three lists which each contain two dataframes: df1 <- data.frame(ID =…
Bonono
  • 827
  • 1
  • 9
  • 18
13
votes
1 answer

How to rbind all the data.frames in your working environment?

I have over 50 data.frames in my working environment that I would like to rbind. Is there a way to rbind the data.frames with out having to type out each date.frame? Example of what I have been doing: df <- rbind(A, B, C, D, E, F) I have tried: df…
Dre
  • 713
  • 1
  • 8
  • 27
13
votes
6 answers

R duplicate a matrix several times and then bind by rows together

I have the following matrix FI1 FI2 YI1 YI2 BAL1 BAL2 GRO1 GRO2 EQ1 EQ2 1 0.22 0.15 0.1 0.1 0.05 0.05 0.05 0.05 0.05 0.05 2 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00 3 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00 4 0.22 0.00 0.0 0.0 0.00…
user2157086
  • 525
  • 1
  • 5
  • 20
13
votes
1 answer

How to avoid renaming of rows when using rbind inside do.call?

I am trying to bind some sub elements of the elements from the list The list OC is as follows > library(quantmod) > OC <- getOptionChain('AAPL', NULL) > str(OC) List of 9 $ Feb 2013:List of 3 ..$ calls :'data.frame': 35 obs. of 7 variables: …
CHP
  • 16,981
  • 4
  • 38
  • 57
12
votes
2 answers

R rbind error row.names duplicates not allowed

There are other issues here addressing the same question, but I don't realize how to solve my problem based on it. So, I have 5 data frames that I want to merge rows in one unique data frame using rbind, but it returns the error: "Error in…
Jecogeo
  • 339
  • 1
  • 4
  • 10
12
votes
2 answers

rbind two data.frame preserving row order and row names

I have a list of data.frame objects which i would like to row append to one another, ie merge(..., all=T). However, merge seems to remove the row names which I need to be kept intact. Any ideas? Example: x = data.frame(a=1:2, b=2:3, c=3:4, d=4:5,…
Alex
  • 19,533
  • 37
  • 126
  • 195
11
votes
4 answers

Add a new row in specific place in a dataframe

Heres my data: > data Manufacturers Models 1 Audi RS5 2 BMW M3 3 Cadillac CTS-V 4 Lexus ISF I would like to add 1 row in the fourth row, like this: > data …
Bruce Brown
  • 217
  • 2
  • 4
  • 8
11
votes
2 answers

How can I prevent rbind() from geting really slow as dataframe grows larger?

I have a dataframe with only 1 row. To this I start to add rows by using rbind df #mydataframe with only one row for (i in 1:20000) { df<- rbind(df, newrow) } this gets very slow as i grows. Why is that? and how can I make this type of code…
Mark
  • 10,754
  • 20
  • 60
  • 81
9
votes
6 answers

Performance of rbind.data.frame

I have a list of dataframes for which I am certain that they all contain at least one row (in fact, some contain only one row, and others contain a given number of rows), and that they all have the same columns (names and types). In case it matters,…
Nick Sabbe
  • 11,684
  • 1
  • 43
  • 57
9
votes
6 answers

Rbind two vectors in R

I have a data.frame with several columns I'd like to join into one column in a new data.frame. df1 <- data.frame(col1 = 1:3, col2 = 4:6, col3 = 7:9) how would I create a new data.frame with a single column that's 1:9?
screechOwl
  • 27,310
  • 61
  • 158
  • 267
9
votes
1 answer

performing something similar to rbind in dplyr or tidyr?

Say with the following data, I am interested in the question of how many unique partners each fruit has? my df: fruit1 fruit2 1 guava kiwi 2 lemon pear 3 pear apple 4 guava kiwi 5 pear guava 6 …
jalapic
  • 13,792
  • 8
  • 57
  • 87
9
votes
2 answers

R 3.0.3 rbind multiple csv files

R 3.0.3: I have 40 csv files all structured the same that I want to rbind into one file so I can calculate the mean of one column. I searched: this website R in a Nutshell R_Intro sources ?rbind Help in RStudio I cannot find the answer. Any…
user3551565
  • 91
  • 1
  • 1
  • 2
9
votes
5 answers

Why does R change the variable type when prepending NA values to a data frame with factors?

I have a problem with the way R coerces variable types when using rbind of two data.frames with NA values. I illustrate by…
tomka
  • 2,516
  • 7
  • 31
  • 45
1
2
3
60 61