R Operators
发布时间:2026-09-15 | 浏览:1
R Language Tutorial
Data Structures
Interview Questions
Data Viz. using R
R Data Analysis
R Machine Learning
Operators in R are symbols that perform operations on variables and values (operands). They allow you to carry out mathematical calculations, logical comparisons, assignments and other operations efficiently.
Arithmetic Operators
Arithmetic operators perform mathematical operations on numeric values or vectors. In R, these operations are applied element-wise when working with vectors.
1. Addition (+)
The values at the corresponding positions of both operands are added.
2. Subtraction (-)
The second operand values are subtracted from the first.
3. Multiplication (*)
The multiplication of corresponding elements of vectors and Integers are multiplied with the use of the '*' operator.
4. Division (/)
The first operand is divided by the second operand with the use of the '/' operator.
The first operand is raised to the power of the second operand.
It returns the remainder after dividing the first operand by the second operand.
Logical Operators
Logical Operators in R simulate element-wise decision operations, based on the specified operator between the operands, which are then evaluated to either a True or False boolean value. Any non-zero integer value is considered as a TRUE value, be it a complex or real number.
1. Element-wise AND (&)
Returns True if both the operands are True.
2. Element-wise OR (|)
Returns True if either of the operands is True.
A unary operator that negates the status of the elements of the operand.
4. Short-circuit AND (&&)
Returns True if both the first elements of the operands are True.
5. Short-circuit OR (||)
Returns True if either of the first elements of the operands is True.
Relational Operators
The Relational Operators in R carry out comparison operations between the corresponding elements of the operands. Returns a boolean TRUE value if the first operand satisfies the relation compared to the second. In logical comparisons, TRUE is internally treated as 1 and FALSE as 0. However, comparisons involving logical values depend on context and type coercion.
1. Less than (<)
Returns TRUE if the corresponding element of the first operand is less than that of the second operand. Else returns FALSE.
2. Less than or equal to (<=)
Returns TRUE if the corresponding element of the first operand is less than or equal to that of the second operand. Else returns FALSE.
3. Greater than (>)
Returns TRUE if the corresponding element of the first operand is greater than that of the second operand. Else returns FALSE.
4. Greater than or equal to (>=)
Returns TRUE if the corresponding element of the first operand is greater or equal to that of the second operand. Else returns FALSE.
5. Not equal to (!=)
Returns TRUE if the corresponding element of the first operand is not equal to the second operand. Else returns FALSE.
When different data types are combined in a vector, R performs type coercion by converting all elements to a common type (usually the most flexible type, such as character).
Assignment Operators
Assignment Operators in R are used to assigning values to various data objects in R. The objects may be integers, vectors or functions. These values are then stored by the assigned variable names.
1. Left Assignment (<- , <<- , =)
Assigns a value to a vector.
2. Right Assignment (-> , ->>)
Assigns value to a vector.
Miscellaneous Operators
Miscellaneous operators in R are special-purpose operators used for tasks such as membership checking ( %in% ) and matrix multiplication ( %*% ).
1. %in% Operator
Checks if an element belongs to a list and returns a boolean value TRUE if the value is present else FALSE.
2. %*% Operator (Matrix Multiplication)
The %*% operator performs matrix multiplication.
Columns of the first matrix must equal rows of the second.
If A is (r × c) and B is (c × r), the result is (r × r).
R Programming Language - Introduction 3 min read
Interesting Facts about R Programming Language 4 min read
R vs Python 5 min read
Environments in R Programming 3 min read
Introduction to RStudio 5 min read
How to Install R and R Studio 4 min read
Creation and Execution of R File in R Studio 5 min read
Clear the Console and the Environment in R Studio 2 min read
Hello World in R Programming 2 min read
Basic Syntax in R Programming 3 min read
Comments in R 3 min read
R Operators 5 min read
R-Keywords 2 min read
Data Types in R 5 min read
R Variables - Creating, Naming and Using Variables in R 5 min read
Scope of Variable in R 5 min read
Dynamic Scoping in R Programming 5 min read
Lexical Scoping in R Programming 4 min read
Taking Input from User in R Programming 7 min read
Printing Output of an R Program 4 min read
Print the Argument to the Screen in R Programming - print() Function 2 min read
Control Statements in R Programming 4 min read
Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch 3 min read
Switch case in R 2 min read
For loop in R 5 min read
R - while loop 5 min read
R - Repeat loop 2 min read
goto statement in R Programming 2 min read
Break and Next statements in R 3 min read
Functions in R Programming 6 min read
Function Arguments in R Programming 4 min read
Types of Functions in R Programming 6 min read
Recursive Functions in R Programming 4 min read
Conversion Functions in R Programming 4 min read
Data Structures in R Programming 4 min read
R Strings 6 min read
R-Vectors 4 min read
R-Lists 6 min read
R - Array 7 min read
R-Matrices 10 min read
R-Factors 4 min read
R-Data Frames 6 min read
R-Object Oriented Programming 7 min read
Classes in R Programming 3 min read
R-Objects 3 min read
Encapsulation in R Programming 3 min read
Polymorphism in R Programming 6 min read
R - Inheritance 7 min read
Abstraction in R Programming 3 min read
Looping over Objects in R Programming 5 min read
S3 class in R Programming 8 min read
Explicit Coercion in R Programming 3 min read
Handling Errors in R Programming 3 min read
Condition Handling in R Programming 5 min read
Debugging in R Programming 3 min read
File Handling in R Programming 3 min read
Reading Files in R Programming 9 min read
Writing to Files in R Programming 2 min read
Working with Binary Files in R Programming 5 min read
Packages in R Programming 5 min read
Data visualization with ggplot2 in R 8 min read
dplyr Package in R Programming 3 min read
Grid and Lattice Packages in R Programming 3 min read
Shiny Package in R Programming 12 min read
tidyr Package in R Programming 13 min read
Tidyverse Packages in R Language 5 min read
Data Munging in R Programming 11 min read
Data Handling in R Programming 3 min read
Importing Data in R Script 3 min read
Exporting Data from scripts in R Programming 6 min read
Working with CSV files in R Programming 3 min read
Working with XML Files in R Programming 3 min read
Working with Excel Files in R Programming 3 min read
Working with JSON Files in R Programming 4 min read
Working with Databases in R Programming 4 min read
Data Visualization in R 4 min read
R - Line Graphs 3 min read
R - Bar Charts 4 min read
Histograms in R language 2 min read
Scatter plots in R Language 3 min read
R - Pie Charts 3 min read
Boxplots in R Language 4 min read
R - Statistics 2 min read
Mean, Median and Mode in R Programming 2 min read
Descriptive Analysis in R Programming 8 min read
Normal Distribution in R 4 min read
Binomial Distribution in R Programming 3 min read
ANOVA (Analysis of Variance) Test in R Programming 3 min read
Covariance and Correlation in R Programming 3 min read
Skewness in R Programming 3 min read
Hypothesis Testing in R Programming 6 min read
Bootstrapping in R Programming 3 min read
Time Series Analysis in R 3 min read
Introduction to Machine Learning in R 4 min read
Setting up Environment for Machine Learning with R Programming 2 min read
Supervised and Unsupervised Learning in R Programming 3 min read
Regression and its Types in R Programming 5 min read
Classification in R Programming 8 min read
Naive Bayes Classifier in R Programming 4 min read
KNN Classifier in R Programming 4 min read
Clustering in R Programming 10 min read
Decision Tree in R Programming 3 min read
Random Forest Approach in R Programming 5 min read
Hierarchical Clustering in R Programming 4 min read
DBScan Clustering in R Programming 3 min read
Deep Learning in R Programming 5 min read
R Interview Questions with Answers 11 min read
Data Science 360 Course 2 min read
AI Engg Course 2 min read