How to divide 2 numbers in R?

This recipe helps you divide 2 numbers in R

Recipe Objective

How to divide two numbers in R ? The division of two numbers is an arithmetic operation of dividing two numbers and storing the output in a vector. The input values can be pre-defined or can be user-defined. The division operation can be done on a single number or a list of input values. This recipe performs the division of two numbers using the / operator.

Explore Interesting IoT Project Ideas for Practice

Step 1 - Define two input vectors

x <- 100 y <- 20

Step 2- Divide the variables

Divide the two input vectors and store the ouput in a third output vector

z <- x/y print(paste("Division of two numbers is:",z))

"Output of the code is" : 5 

Step 3- User defined input vectors

Division of two numbers can also be done , with user defined values using the following syntax

a <- readline(prompt="enter the first input value : ") b <- readline(prompt="enter the second input value : ")

 "Output of the line is" :
enter the first input value : 100
enter the second input value : 20

The user defined input values are character type , they are converted into integer type for performing the division operation

a <- as.integer(a) b <- as.integer(b)

Step 4 - Add two user defined vectors

Adding two user defined input vectors and storing the output in a third vector

c <- a / b print(paste("Addition of user defined two numbers is:",c))

"Output of the code is" : Addition of two numbers is 5

Join Millions of Satisfied Developers and Enterprises to Maximize Your Productivity and ROI with ProjectPro - Read ProjectPro Reviews Now!

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Build an End-to-End AWS SageMaker Classification Model
MLOps on AWS SageMaker -Learn to Build an End-to-End Classification Model on SageMaker to predict a patient’s cause of death.

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

Mastering A/B Testing: A Practical Guide for Production
In this A/B Testing for Machine Learning Project, you will gain hands-on experience in conducting A/B tests, analyzing statistical significance, and understanding the challenges of building a solution for A/B testing in a production environment.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

House Price Prediction Project using Machine Learning in Python
Use the Zillow Zestimate Dataset to build a machine learning model for house price prediction.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.