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.

To calculate the mean of each row in a matrix in R, you would use the ______ function.

  • rowMeans()
  • colMeans()
  • mean()
  • apply()
To calculate the mean of each row in a matrix in R, you would use the rowMeans() function. The rowMeans() function computes the mean values across each row of the matrix.

In R, the ______ function can be used to create a scatter plot with a smooth line fitted to the data.

  • scatterplot()
  • smoothplot()
  • lines()
  • loess()
The loess() function in R can be used to fit a smooth line to a scatter plot. It uses the locally weighted scatterplot smoothing technique to estimate a smooth curve that captures the general trend in the data.

What is the difference between "==" and "=" in R?

  • "=" is not used in R
  • "==" is used for assignment and "=" is used for comparison
  • "==" is used for comparison and "=" is used for assignment
  • There is no difference
In R, "==" is a comparison operator used to test for equality, while "=" is used for assignment, especially in the context of function arguments. However, "<-" is more commonly used for assignment.

The ______ function in R can be used to generate a histogram of a numeric vector.

  • hist()
  • plot()
  • barplot()
  • boxplot()
The hist() function in R can be used to generate a histogram of a numeric vector. The hist() function divides the range of the data into equal intervals called bins and counts the number of observations falling into each bin, creating a visual representation of the distribution of the data.

Imagine you're working with a large data set in R and need to create a bar chart that clearly communicates the key findings. How would you approach this task?

  • Simplify the chart by focusing on the most important categories
  • Use distinct colors or patterns to enhance differentiation
  • Provide clear labels and a legend for better understanding
  • All of the above
When working with a large data set in R and aiming to create a bar chart that clearly communicates the key findings, it is important to simplify the chart by focusing on the most important categories. Use distinct colors or patterns to enhance differentiation between the bars. Provide clear labels and a legend to ensure better understanding of the chart. The combination of these approaches will help create an effective bar chart that effectively communicates the key findings.

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).