演算子
> 1+2
[1] 3
用法の不明な演算子は、
> ?"+"
のようにすることで、ヘルプを確認できます。
演算子 |
機能 |
+ |
Plus, can be unary or binary |
- |
Minus, can be unary or binary |
* |
Multiplication, binary |
/ |
Division, binary |
%% |
Modulus, binary |
%/% |
Integer divide, binary |
^ |
Exponentiation, binary |
演算子 |
機能 |
== |
Equal to, binary |
!= |
|
< |
Less than, binary |
> |
Greater than, binary |
>= |
Greater than or equal to, binary |
<= |
Less than or equal to, binary |
論理演算子 (Logical Operators)
演算子 |
機能 |
& |
And, binary, vectorized |
| |
Or, binary, vectorized |
! |
Unary not |
&& |
And, binary, not vectorized |
|| |
Or, binary, not vectorized |
代入演算子 (Assignment Operator)
演算子 |
機能 |
<- |
Left assignment, binary |
<<- |
= ※1 |
-> |
Right assignment, binary |
->> |
※1 only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions.
> a = 1
> print(a)
[1] 1
> b <- 2
> print(b)
[1] 2
> 3 -> c
> print(c)
[1] 3
Variable Assignment - R Variables | TutorialsPoint
行列の乗法 (Matrix multiplication)
演算子 |
機能 |
%*% |
Matrix product, binary [行列積] |
%o% |
Outer product, binary [外積] |
%x% |
Kronecker product, binary [クロネッカー積] |
X %o% Y
は、outer(X, Y, FUN = "*", ...)
と同等です。
X %x% Y
は、kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...)
と同等です。
その他
演算子 |
機能 |
~ |
Tilde, used for model formulae, can be either unary or binary |
: |
Sequence, binary (in model formulae: interaction) |
%x% |
Special binary operators, x can be replaced by any valid name |
%in% |
Matching operator, binary (in model formulae: nesting) |
$ |
List subset, binary |
? |
Help |
特殊演算子 (Special operators)
「%」で囲まれた演算子の総称で、ユーザー定義の中置演算子 (infix operators) を表します。
次の演算子は、baseパッケージで定義されています。
10.3.4 Special operators - R Language Definition
magrittr
演算子 |
機能 |
%>% |
Pipe an object forward into a function or call expression. |
%<>% |
Pipe an object forward into a function or call expression and update the lhs object with the resulting value. |
%T>% |
Pipe a value forward into a function- or call expression and return the original value instead of the result. |
%$% |
Expose the names in lhs to the rhs expression. |