cbind in R – Column bind using cbind function

Column Bind – Cbind  in R appends or combines vector, matrix or data frame by columns.Lets see column bind in R with an example.


Note : The number of rows in two dataframes needs to be same.


Syntax for Cbind in R:


x1,x2 can be data frame, matrix or vector.

Example of Cbind in R:

Lets see how to implement Cbind function in R with an example. First lets create two data frames

#Create two data frames
df1 = data.frame(name = c("Rahul","joe","Adam","Brendon"), married_year = c(2016,2015,2016,2008))
df2 = data.frame(Birth_place = c("Delhi","Seattle","London","Moscow"), Birth_year = c(1988,1990,1989,1984))
df1 will be 

    name      married_year

1   Rahul           2016

2     joe              2015

3    Adam          2016

4  Brendon       2008


  df2 will be 

  Birth_place   Birth_year

1       Delhi           1988

2     Seattle          1990

3      London        1989

4      Moscow       1984


Now, column bind (cbind) these two data frames as shown below

# cbind in R: column bind the data frames.

so the resultant column bind data frame in R will be

     name   married_year Birth_place  Birth_year

1   Rahul           2016               Delhi        1988

2     joe              2015             Seattle       1990

3    Adam          2016            London       1989

4 Brendon        2008           Moscow       1984

cbind function in r                                                                                                           cbind in R