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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

Learn to Build a Neural network from Scratch using NumPy
In this deep learning project, you will learn to build a neural network from scratch using NumPy

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

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.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

AWS Project to Build and Deploy LSTM Model with Sagemaker
In this AWS Sagemaker Project, you will learn to build a LSTM model on Sagemaker for sales forecasting while analyzing the impact of weather conditions on Sales.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data