rbind.data.frame
Create a Data Frame from Rows

Description

Creates a data frame from rows.

Usage

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

Arguments

... individual data frames or vectors.
deparse.level This argument is not used in rbind.data.frame at present.
Value
returns a data frame combining the arguments by rows.
Hints
This is a method for the generic function rbind() for objects that inherit from class "data.frame". If none of the arguments is a data frame, you must call the method explicitly, rather than by calling rbind(). The arguments should be either compatible data frames (with the same set of variables) or lists whose elements are suitable to be added onto the corresponding variables in a data frame argument. The first data frame encountered as an argument determines the form of the output. That is, the result of the function is a data frame whose variables are factors, ordered factors, numeric variables, and other kinds of variables according to what is found in the first data frame argument encountered.
Warning
This method is not a very efficient way to build a data frame in the case where many rows are added in a loop. It does a lot of checking and re-computing for each loop. The following alternatives are faster:
See Also
rbind, data.frame.
Examples

df <- data.frame(a = c(1:5), b = (1:5)^2) # add 2 new rows rbind(df, c(2, 3), c(5, 6)) rbind.data.frame() rbind(df, matrix(c(2, 3, 5, 6), nrow =2)) # Error: names do not match previous names rbind(df, matrix(c(2, 3, 5, 6), nrow = 2, dimnames = list(NULL, c("a", "b")))) # OK. rbind(matrix(c(2, 3, 5, 6), nrow = 2, dimnames = list(NULL, c("a", "b"))), c(12, 34), df) # Insert three rows before df

df1 <- data.frame(a = c("Red", "Green","Blue","White","Black"), b = (1:5)^2) rbind(df1, data.frame(a = "Yellow", b = 36)) # add one row rbind(df1, data.frame(a = c("Yellow","Pink"), b= c(36,49))) # add two rows rbind(df1, data.frame(aa = c("Yellow","Pink"), bb= c(36,49))) # Error: names do not match previous names

rbind(df1, c("Yellow", 36)) # Warning: invalid factor level, NAs generated. rbind(df1, c("Yellow", "36")) # Warning: invalid factor level, NAs generated.

rbind(df1, list(a = c("Yellow","Pink"), b= c(36,49))) # Warning: invalid factor level, NAs generated.

Package base version 6.0.0-69
Package Index