I will post a method for combining the columns and rows of two datasets in R. I have created two datasets simply for this purpose.
name=c("Jack","Kate","John","Mark","Rut")
math=c(90,85,95,75,80)
eng=c(85,90,90,88,95)
avg=c(87.5,87.5,92.55,81.5,87.5)
grade=data.frame(name,math,eng,avg)
print(grade)
name math eng avg
1 Jack 90 85 87.50
2 Kate 85 90 87.50
3 John 95 90 92.55
4 Mark 75 88 81.50
5 Rut 80 95 87.50
country=c("USA","Spain","France","Germany","Korea")
gender=c("Male","Female","Male","Male","Female")
info=data.frame(country,gender)
print(info)
country gender
1 USA Male
2 Spain Female
3 France Male
4 Germany Male
5 Korea Female
And now, let’s combine these two datasets.
newinfo=cbind(grade,info) print(newinfo) name math eng avg country gender 1 Jack 90 85 87.50 USA Male 2 Kate 85 90 87.50 Spain Female 3 John 95 90 92.55 France Male 4 Mark 75 88 81.50 Germany Male 5 Rut 80 95 87.50 Korea Female
I have combined these two tables into one. In fact, combining columns is simple because you can just put them side by side. However, when combining rows, it is important to check if the names of each column are the same before merging to prevent data from being mixed up.

I have created two simple data tables again.
name=c("Jack","Kate","John","Mark","Rut")
math=c(90,85,95,75,80)
eng=c(85,90,90,88,95)
avg=c(87.5,87.5,92.55,81.5,87.5)
grade1=data.frame(name,math,eng,avg)
print(grade1)
name math eng avg
1 Jack 90 85 87.50
2 Kate 85 90 87.50
3 John 95 90 92.55
4 Mark 75 88 81.50
5 Rut 80 95 87.50
name=c("Min","Hoon","Yoon","Kim","Park")
math=c(100,80,90,88,90)
eng=c(70,95,88,92,85)
avg=c(85,87.5,89,90,87.5)
grade2=data.frame(name,math,eng,avg)
print(grade2)
name math eng avg
1 Min 100 70 85.0
2 Hoon 80 95 87.5
3 Yoon 90 88 89.0
4 Kim 88 92 90.0
5 Park 90 85 87.5
The columns in these two data tables have the same column names. Now, I want to combine the rows of these two tables to create one table. For this, I will use the rbind()
newgrade=rbind (grade1,grade2) print(newgrade) name math eng avg 1 Jack 90 85 87.50 2 Kate 85 90 87.50 3 John 95 90 92.55 4 Mark 75 88 81.50 5 Rut 80 95 87.50 6 Min 100 70 85.00 7 Hoon 80 95 87.50 8 Yoon 90 88 89.00 9 Kim 88 92 90.00 10 Park 90 85 87.50
