R Tutorial R Charts & Graphs R Statistics R References

R - right assignment operator example



Right Assignment operator assigns value of right hand side expression to right hand side operand. R has two such kind of operators (-> and ->>).

Right assignment operator (->)

It assigns value of left hand side expression to right hand side operand.

10 -> x1
c(10, 20, 30) -> x2
matrix(c(10, 20, 30, 40, 50, 60), nrow=2) -> x3

#printing all variables
print(x1)
print(x2)

cat("\n")
print(x3)

The output of the above code will be:

[1] 10
[1] 10 20 30

     [,1] [,2] [,3]
[1,]   10   30   50
[2,]   20   40   60

Right assignment operator (->>)

It assigns value of left hand side expression to right hand side operand. It has same functionality as (->) but as global assignment operator.

10 ->> x1
c(10, 20, 30) ->> x2
matrix(c(10, 20, 30, 40, 50, 60), nrow=2) ->> x3

#printing all variables
print(x1)
print(x2)

cat("\n")
print(x3)

The output of the above code will be:

[1] 10
[1] 10 20 30

     [,1] [,2] [,3]
[1,]   10   30   50
[2,]   20   40   60

❮ R - Operators