Assignment Operators in R Programming Language

Rumman Ansari   Software Engineer   2023-03-24   5867 Share
☰ Table of Contents

Table of Content:


Assignment Operators

These operators are used to assign values to vectors.

Operator Description Example

<−

or

=

or

<<−

Called Left Assignment
a1 <- c(3,1,TRUE,2+3i)
a2 <<- c(3,1,TRUE,2+3i)
a3 = c(3,1,TRUE,2+3i)
print(a1)
print(a2)
print(a3)

it produces the following result −

[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i

->

or

->>

Called Right Assignment
c(3,1,TRUE,2+3i) -> a1
c(3,1,TRUE,2+3i) ->> a2 
print(a1)
print(a2)

it produces the following result −

[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i

More Eamples

The operators <- and = can be used, almost interchangeably, to assign to variable in the same environment.

The <<- operator is used for assigning to variables in the parent environments (more like global assignments). The rightward assignments, although available are rarely used.

> x <- 5
> x
[1] 5
> x = 9
> x
[1] 9
> 10 -> x
> x
[1] 10