![]() |
VOOZH | about |
In this article, we will discuss how we Combine Vectors, Matrices, or Data Frames by Rows in R Programming Language using rbind function.
The rbind function combines or concatenates data frames or matrices by rows. the rbind stands for row binds it shows that it appends rows of one object to another.
Syntax:
rbind(x1, x2, ..., deparse.level = 1)
Parameters:x1, x2: vector, matrix, data frames
deparse.level: This value determines how the column names are generated. The default value of deparse.level is 1.
We will create two vectors and combine them with the help of rbinf function.
Output:
[1] 2 3 4 5 6 7
[1] 2 5
[,1] [,2] [,3] [,4] [,5] [,6]
x 2 3 4 5 6 7
y 2 5 2 5 2 5
We will create two matrix and combine them with the help of rbinf function.
Output:
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 15 18
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
[4,] 10 13 16
[5,] 11 14 17
[6,] 12 15 18
We will create two data frame and combine them with the help of rbinf function.
Output:
Name Age Score
1 Anurag 25 90
2 Nishant 30 85
3 Jayesh 22 92
Name Age Score
1 Vipul 28 88
2 Shivang 35 91
3 Pratham 27 89
Name Age Score
1 Anurag 25 90
2 Nishant 30 85
3 Jayesh 22 92
4 Vipul 28 88
5 Shivang 35 91
6 Pratham 27 89
We will create two data frames having missing values and combine them with the help of rbinf function.
Output:
Name Age Score
1 Anurag 25 90
2 Nishant NA 85
3 Jayesh 22 NA
Name Age Score
1 Vipul NA 88
2 Shivang 35 NA
3 Pratham 27 89
Name Age Score
1 Anurag 25 90
2 Nishant NA 85
3 Jayesh 22 NA
4 Vipul NA 88
5 Shivang 35 NA
6 Pratham 27 89
Here are the some of the examples for Combine Vectors, Matrix or Data Frames by Rows in R Programming Language. for combining rows it is necessary that it contain same amount of columns.