How to add 2 numbers in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to add 2 numbers in R?

How to add 2 numbers in R?

This recipe helps you add 2 numbers in R

0

Recipe Objective

How to add two numbers in R? The addition of two numbers is an arithmetic operation of adding the two numbers and storing the output in a vector. The input values can be pre-defined or can be user-defined. The addition operation can be done on a single number or a list of input values. sum () is the function used for performing the operation. This recipe performs the addition of two numbers using the + as well as the sum () function..

Step 1- Create 2 input vectors

x <- 10 y <- 20

Step 2- Add the vectors

Add the two input vectors and store the output value in a third vector

z <- x+y print(paste("Addition of two numbers is:",z))
"Output of the code is : Addition of two numbers is"  : 30 

Step 3- User defined input vectors

Addition 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 : 10
enter the second input value : 20

The user defined input values are character type , they are converted into integer type for performing the addition 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" : 30 

Step 5- Using built in function sum()

x <- c(10,20) print(paste("Addition of two numbers is :",sum(x)))
"Output of the code is : Addition of two numbers is" : 30

Relevant Projects

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

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.

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.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

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

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.