What is cbind in R?

What is cbind in R?

What is cbind in R?

This recipe explains what is cbind in R


Recipe Objective

What is cbind in R? Cbind () — column bind function is used for merging two data frames together given that the number of rows in both the data frames are equal. cbind can append vectors, matrices or any data frame by columns. This recipe demonstrates an example using cbind.

Step 1- Define two dataframes

df1 <- data.frame(name = c('A','B','C','D','E','F'), age = c(22,25,28,19,15,23)) print(df1)
"df1 is":
  name age
1    A  22
2    B  25
3    C  28
4    D  19
5    E  15
6    F  23
df2 <- data.frame(gender = c('Male','Male','Female','Male','Female','Female')) print(df2)
"df2 is": 
1   Male
2   Male
3 Female
4   Male
5 Female
6 Female

Step 2 - Apply cbind()

final_data <- cbind(df1,df2) print(final_data)
"Output of code is": 
  name age gender
1    A  22   Male
2    B  25   Male
3    C  28 Female
4    D  19   Male
5    E  15 Female
6    F  23 Female

Relevant Projects

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.