R - left assignment operator example

Left Assignment operator assigns value of right hand side expression to left hand side operand. R has three such kind of operators (=, <- and <<-).

Left assignment operator (=)

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

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

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

cat("\n")
print(x3)

The output of the above code will be:

 10
 10 20 30

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

Left assignment operator (<-)

It assigns value of right hand side expression to left hand side operand. It is same as (=) except it can be used anywhere, whereas the operator (=) is only allowed at the top level.

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

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

cat("\n")
print(x3)

The output of the above code will be:

 10
 10 20 30

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

Left assignment operator (<<-)

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

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

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

cat("\n")
print(x3)

The output of the above code will be:

 10
 10 20 30

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

❮ R - Operators

5
{"ft_lang_label":"__label__en","ft_lang_prob":0.719911,"math_prob":0.9995846,"size":1416,"snap":"2022-05-2022-21","text_gpt3_token_len":497,"char_repetition_ratio":0.14447592,"word_repetition_ratio":0.56273764,"special_character_ratio":0.4435028,"punctuation_ratio":0.1588785,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99780995,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-19T22:48:45Z\",\"WARC-Record-ID\":\"<urn:uuid:aec5a5c0-5367-4e45-b360-a5e2fdc6a841>\",\"Content-Length\":\"23693\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9db79b40-8217-4e9d-8d0e-ef7392aeb2eb>\",\"WARC-Concurrent-To\":\"<urn:uuid:2601b756-50a5-47d1-aac7-d9c4b533d7e3>\",\"WARC-IP-Address\":\"104.154.71.199\",\"WARC-Target-URI\":\"https://www.alphacodingskills.com/r/notes/r-operator-left-assignment.php\",\"WARC-Payload-Digest\":\"sha1:KUEM66A2PLNAUOAIW6TKUI2XHGPXQOT5\",\"WARC-Block-Digest\":\"sha1:AAEGYUIU6TUKXA5FUT4BFIY3OFN442BV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320301592.29_warc_CC-MAIN-20220119215632-20220120005632-00147.warc.gz\"}"}