R - (Mathematical|Logical) Operators

Card Puncher Data Processing

Mathematical

# Addition
> 2+2
[1] 4
# Multiplication
> 2*3
[1] 6
# Division
> 4/2
[1] 2
# Power
> 2^3
[1] 8

Logical

?base::logic
& boolean and
| boolean for
xor exactly or
! not
any any true
all all true
  • Not (!)
> !TRUE
[1] FALSE

Many operations in R are vectorized.

> x=1:4;y=6:3
> x
[1] 1 2 3 4
> y
[1] 6 5 4 3
# Logical
> x>2
[1] FALSE FALSE  TRUE  TRUE
> x>=2
[1] FALSE  TRUE  TRUE  TRUE
> y==1
[1] FALSE FALSE FALSE FALSE

Comparison

?Comparison
< Less than
> Greater than
== Equal to
Less than or equal to
>= Greater than or equal to
!= Not equal to
%in% Group membership
is.na Is NA
!is.na Is not NA

Assignment

The symbol ← and = are the assignment operator.

x <- 1

is equivalent to:

x = 1

Proof:

> x<-1
> y=1
> x==y
[1] TRUE

Sequence

The : operator is used to create integer sequences.

> x=3:5
> x
[1] 3 4 5

Subset

R - Subset Operators (Extract or Replace Parts of an Object)





Discover More
Card Puncher Data Processing
R - Colon (:) Operator - Sequence generator

The Colon (:) Operator generate regular sequences. where: from, starting value of sequence and to: (maximal) end value of the sequence. a, b factors of the same length. “”
Card Puncher Data Processing
R - Subset Operators (Extract or Replace Parts of an Object)

In the Data Manipulation category, you have the subset operators: [ [[ $ This operators acts on: vectors, matrices, arrays lists data.frame to extract or replace parts. See also:...
Card Puncher Data Processing
R - Vector

The Vector in R contains elements of the same class. A Vector with different class of objects is a list. A vector (as every object) can also have . Almost all data in R is a vector or is based upon...



Share this page:
Follow us:
Task Runner