In R, if a variable is not found in the local environment of a function, the function will look in the ______ environment.

  • Global
  • Parent
  • Child
  • Calling
In R, if a variable is not found in the local environment of a function, the function will look in the parent environment. This allows functions to access variables defined in higher-level environments, such as variables defined outside the function but within the parent environment.

The ifelse() function in R has the syntax ifelse(condition, ________, ________).

  • value_if_true and value_if_false
  • code_if_true and code_if_false
  • result_if_true and result_if_false
  • condition_if_true and condition_if_false
The ifelse() function in R has the syntax ifelse(condition, value_if_true, value_if_false). It evaluates the condition and returns the value_if_true if the condition is true, and the value_if_false if the condition is false. This function allows for vectorized conditional operations.

R's memory management can be inefficient as it stores all data in _________, which might be an issue with larger datasets.

  • Cache
  • Hard Disk
  • RAM
  • Registers
R stores all data in RAM, and as such, it might struggle with large datasets. This can sometimes limit its speed and efficiency, particularly in a data-intensive environment. However, there are packages and strategies to manage and overcome this limitation.

What is the primary use case for nested functions in R?

  • Encapsulating helper functions within a larger function
  • Reducing code duplication and improving modularity
  • Implementing complex algorithms or workflows
  • All of the above
The primary use case for nested functions in R is to encapsulate helper functions within a larger function. Nested functions can help in reducing code duplication, improving code modularity, and organizing related functionality together. They are especially useful when implementing complex algorithms or workflows that require multiple steps or subroutines.

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.

In R, the ______ function can be used to check if an object is a matrix.

  • is.matrix()
  • is.vector()
  • is.data.frame()
  • is.array()
In R, the is.matrix() function can be used to check if an object is a matrix. It returns TRUE if the object is a matrix and FALSE otherwise. This function is useful for verifying the type of an object before applying operations specific to matrices.

How would you find the max or min value in each column or row of a matrix or data frame in R?

  • Use the apply() function with the appropriate margin argument
  • Use the max() or min() function with the appropriate argument
  • Use the colMax() or rowMax() function for matrices
  • Use the max.col() or min.col() function for data frames
To find the max or min value in each column or row of a matrix or data frame in R, you can use the apply() function. By specifying the appropriate margin argument (1 for rows, 2 for columns), you can apply the max() or min() function across the specified dimension.