Rの演算子 - GeeksforGeeks
原題: R Operators - GeeksforGeeks
分析結果
- カテゴリ
- AI
- 重要度
- 60
- トレンドスコア
- 24
- 要約
- この記事では、Rプログラミング言語における演算子の種類とその使用方法について解説しています。基本的な算術演算子から論理演算子、比較演算子、ビット演算子まで幅広くカバーし、各演算子の具体的な例を通じて理解を深めることができます。Rを使ったデータ分析やプログラミングの基礎を学ぶ上で重要な内容です。
- キーワード
R Operators - GeeksforGeeks Courses Tutorials Interview Prep R Language Tutorial Fundamentals Functions OOPs Data Structures File Handling Project Ideas Interview Questions R Quiz Data Viz. using R R Data Analysis R Machine Learning R Operators Last Updated : 9 Apr, 2026 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. Operators in R 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. R a <- c ( 1 , 0.1 ) b <- c ( 2.33 , 4 ) print ( a + b ) Output [1] 3.33 4.10 2. Subtraction (-) The second operand values are subtracted from the first. R a <- 6 b <- 8.4 print ( a - b ) Output [1] -2.4 3. Multiplication (*) The multiplication of corresponding elements of vectors and Integers are multiplied with the use of the '*' operator. R b = c ( 4 , 4 ) c = c ( 5 , 5 ) print ( b * c ) Output [1] 20 20 4. Division (/) The first operand is divided by the second operand with the use of the '/' operator. R a <- 10 b <- 5 print ( a / b ) Output [1] 2 5. Power (^) The first operand is raised to the power of the second operand. R a <- 4 b <- 5 print ( a ^ b ) Output [1] 1024 6. Modulo (%%) It returns the remainder after dividing the first operand by the second operand. R a <- c ( 2 , 22 ) b <- c ( 2 , 4 ) print ( a %% b ) Output [1] 0 2 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. R a <- c ( TRUE , 0.1 ) b <- c ( 0 , 4+3i ) print ( a & b ) Output [1] FALSE TRUE 2. Element-wise OR (|) Returns True if either of the operands is True. R a <- c ( TRUE , 0.1 ) b <- c ( 0 , 4+3i ) print ( a | b ) Output [1] TRUE TRUE 3. NOT (!) A unary operator that negates the status of the elements of the operand. R a <- c ( 0 , FALSE ) print ( ! a ) Output [1] TRUE TRUE 4. Short-circuit AND (&&) Returns True if both the first elements of the operands are True. R a <- c ( TRUE , 0.1 ) b <- c ( 0 , 4+3i ) print ( a [ 1 ] && b [ 1 ]) Output [1] FALSE 5. Short-circuit OR (||) Returns True if either of the first elements of the operands is True. R a <- c ( TRUE , 0.1 ) b <- c ( 0 , 4+3i ) print ( a [ 1 ] || b [ 1 ]) Output [1] 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. R a <- c ( TRUE , 0.1 , "apple" ) b <- c ( 0 , 0.1 , "bat" ) print ( a < b ) Output [1] FALSE FALSE TRUE 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. R a <- c ( TRUE , 0.1 , "apple" ) b <- c ( TRUE , 0.1 , "bat" ) c <- as.character ( a ) d <- as.character ( b ) print ( c <= d ) Output [1] TRUE TRUE TRUE 3. Greater than (>) Returns TRUE if the corresponding element of the first operand is greater than that of the second operand. Else returns FALSE. R a <- c ( TRUE , 0.1 , "apple" ) b <- c ( TRUE , 0.1 , "bat" ) print ( a > b ) Output [1] FALSE FALSE 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. R a <- c ( TRUE , 0.1 , "apple" ) b <- c ( TRUE , 0.1 , "bat" ) print ( a >= b ) Output [1] TRUE TRUE 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). R a <- c ( TRUE , 0.1 , 'apple' ) b <- c ( 0 , 0.1 , "bat" ) print ( a != b ) Output [1] TRUE FALSE TRUE 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. R vec1 = c ( "ab" , TRUE ) print ( vec1 ) Output [1] "ab" "TRUE" 2. Right Assignment (-> , ->>) Assigns value to a vector. R c ( "ab" , TRUE ) ->> vec1 print ( vec1 ) Output [1] "ab" "TRUE" 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. R val <- 0.1 a <- c ( TRUE , 0.1 , "apple" ) print ( val %in% a ) Output [1] TRUE 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 mat = matrix ( c ( 1 , 2 , 3 , 4 , 5 , 6 ), nrow = 2 , ncol = 3 ) print ( mat ) print ( t ( mat )) pro = mat %*% t ( mat ) print ( pro ) Output [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 [,1] [,2] [1,] 35 44 [2,] 44 56 Comment Article Tags: Article Tags: R Language AI-ML-DS With R Explore Introduction 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 Fundamentals of R 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 Variables 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 Input/Output 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 Flow 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 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 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 Object Oriented Programming 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 Error Handling 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 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 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 Interfaces 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 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 Statistics 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