What happens when you apply relational operations on 2 vectors of equal and unequal length in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

What happens when you apply relational operations on 2 vectors of equal and unequal length in R?

What happens when you apply relational operations on 2 vectors of equal and unequal length in R?

This recipe explains what happens when you apply relational operations on 2 vectors of equal and unequal length in R

0

Recipe Objective

Vector is a type of object or data structure in R-language. They are designed to store multiple values of same data-type. For example: if you want to store different 50 food items for each cuisine, you don't need to create 50 variables for each cuisine but just a vector of length 50 of datatype character.

Note: It can not have a combination of any two datatype. It has to be homogeneous in nature.

Relational operations between two vector is where every element of vector is compared to the corresponding element in another vector. We use different Relational operators to carry out this task. The output of the operation is a boolean vector.

This recipe demonstrates relational operation with two examples:

  1. comparing 2 vectors with equal length
  2. comparing 2 vectors with unequal length

1. comparing 2 vectors with equal length

Step 1: Creating 2 vectors

We use combine function "c()" to create a vector

a = c(2,5,8,9,10) b = c(5,6,10,20,2)

Step 2: Element-wise comparison

We use relational operator greater than (">") to illustrate this operation. This gives us a boolean vector specifying whether the condition was met or not

print(a>b)
[1] FALSE FALSE FALSE FALSE  TRUE

2. comparing 2 vectors with unequal length

Step 1: Creating 2 vectors

We use combine function "c()" to create a vector

a = c(2,5,8,9,10) b = c(5,6,10)

Step 2: Element-wise comparison

We use relational operator greater than (">") to illustrate this operation. This gives us a boolean vector specifying whether the condition was met or not

print(a>b)
Warning message in a > b:
"longer object length is not a multiple of shorter object length"
[1] FALSE FALSE FALSE  TRUE  TRUE

Note: it gives a warning message ""longer object length is not a multiple of shorter object length" as well as it returns TRUE for every extra element that is present in the longer vector

Relevant Projects

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

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.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.