How to divide 2 numbers in R?

How to divide 2 numbers in R?

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..

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

Relevant Projects

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

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

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

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

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.

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.

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.

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.