Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to implement cbind, rbind and merge funcion in R?

Description

To implement the cbind, rbind and merge funcion using R programming.

Process

Cbind:

   This function combines vector, matrixor data frame by columns.

   Row of two datasets must be equal.

R Function : cbind()

Rbind:

   Thisfunction combines vector, matrixor data frame by rows.

   Column names and the number of columnsof the two dataframes needs to be same.

R Function : rbind()

Merge:

   This function is used to combine or mergetwo data frames by common column and row names.

R Function : merge()
Sapmle Code

#rbind, cbind, merge function

#Read File
print(getwd())
setwd(“/home/soft13”)
print(getwd())
data<-read.csv(‘my_input.csv’)
View(data)

#cbind
age<-c(23,22,34,24,26,27,30,27)
data_1<-cbind(data,age)
print(data_1)

#rbind
id<-c(9:10)
name salary<-c(583.90,672.00)
dept<-c(“BE”,”Management”)
age<-c(24,32)
stringsAsFormats=FALSE
newdata<-data.frame(id,name,salary,dept,age)
data_2<-rbind(data_1,newdata)
print(data_2)

#merge
id<-c(1:10)
place<-c(“Russia”,”Madurai”,”China”,”india”,”Italy”,”Chennai”,”UK”,”USA”,”Kenya”,”Britain”)
datanew2<-data.frame(id,place)
merged<-merge(data_2,datanew2,by.x=c(“id”),by.y=c(“id”))
print(merged)

Screenshots
implement cbind, rbind and merge funcion in R
rbind, cbind, merge function
Read file
Column names and the number of columnsof the two dataframes