Assigning values to variables in R programming – assign() Function

In R programming, assign() method is used to assign the value to a variable in an environment.

Syntax : assign(variable, value)
Return : Return the variable having value assigned.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Using assign() method
assign("gfg", 10)
  
print(gfg)

chevron_right


Output:

[1] 10

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Using assign() method
assign("gfg", 20.12345)
  
print(gfg)

chevron_right


Output:

[1] 20.12345
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.