Suppose you're asked to write a function in R that uses a global variable. How would you do it?

  • Define the global variable outside of the function and access it within the function
  • Define the global variable inside the function and mark it as global using the global() function
  • Define the global variable inside the function and use the global_var() keyword
  • None of the above
To write a function in R that uses a global variable, you would define the global variable outside of the function and access it within the function. Since global variables are accessible from anywhere in the program, the function can directly reference and modify the global variable as needed.
Add your answer
Loading...

Leave a comment

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