Can you explain the use of global and local variables in R?

  • Global variables can be accessed anywhere in the code, while local variables can only be accessed within the function they were defined
  • Global variables can only be accessed within the function they were defined, while local variables can be accessed anywhere in the code
  • None of the above
  • There's no such thing as global and local variables in R
In R, a variable that is defined outside of any function is known as a global variable and it can be accessed from anywhere in the code. On the other hand, a variable that is defined inside a function is known as a local variable, and it can only be accessed within that function.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *