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.

In R, a basic scatter plot is created using the ______ function.

  • scatterplot()
  • plot()
  • points()
  • scatter()
In R, a basic scatter plot is created using the plot() function. It allows you to visualize the relationship between two numeric variables by plotting the data points as individual points on the graph.

Which operator is used to assign a value to a variable in R?

  • ->
  • <-
  • =
  • All of the above
The '<-' operator is commonly used in R for assignment, although the '=' operator can also be used. However, '<-' is generally preferred because it makes the code more readable and avoids confusion with the '=' operator used for passing arguments to functions.

The switch() function in R can be used as an alternative to ________ if-else statements.

  • nested
  • vectorized
  • nested and vectorized
  • multiple
The switch() function in R can be used as an alternative to multiple if-else statements. It evaluates a given expression and matches it to a set of predefined cases. The corresponding case is executed, providing a more concise way to handle multiple conditional branches.

Suppose you're given a numeric vector in R and asked to calculate its mode. How would you do it?

  • Use a custom function that counts frequencies and identifies the most frequent value
  • Use the mode() function directly on the numeric vector
  • Use the median() function to determine the central value
  • Use the max() function to find the maximum value
To calculate the mode of a numeric vector in R, you would use a custom function that counts the frequencies of values and identifies the most frequent value(s) as the mode(s).

How do you create an array in R?

  • Using the array() function
  • Using the matrix() function
  • Using the list() function
  • Using the data.frame() function
In R, an array is created using the array() function. The array() function allows you to specify the values of the array, the dimensions, and other parameters such as dimension names. You can pass a vector of values and specify the dimensions to create the desired array structure.

Describe a situation where you would prefer to use paste0() over paste() in R.

  • None of the above
  • When you want to concatenate a large number of strings
  • When you want to concatenate strings with a separator
  • When you want to concatenate strings without a separator
You would prefer to use 'paste0()' over 'paste()' in R when you want to concatenate strings without a separator. The 'paste0()' function is a variation of the 'paste()' function that does not include a separator by default.

In R, to prematurely exit a for loop, you can use the ______ keyword.

  • Next
  • Skip
  • Break
  • Exit
In R, the break keyword is used to prematurely exit a for loop. When encountered, the break statement immediately terminates the loop and execution continues with the next statement after the loop.

To calculate the mode of a factor in R, you could convert it to a ______ and then use a custom mode function.

  • numeric vector
  • character vector
  • logical vector
  • complex vector
To calculate the mode of a factor in R, you could convert it to a numeric vector (using as.numeric()) and then use a custom mode function that is designed to work with numeric vectors.

Imagine you're working with a large data set in R and need to perform operations on a data frame that's not memory-efficient. How would you handle this situation?

  • Use data.table package for memory-efficient operations
  • Split the data frame into smaller subsets for processing
  • Remove unnecessary columns from the data frame
  • All of the above
All of the mentioned strategies can be used to handle a large data frame that is not memory-efficient. Using the data.table package, splitting the data frame, and removing unnecessary columns are effective ways to optimize memory usage and improve processing efficiency.