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.

Imagine you're asked to optimize a slow-running for loop in R. What are some strategies you could use to improve its performance?

  • Use vectorized operations
  • Preallocate output objects
  • Minimize unnecessary calculations inside the loop
  • All of the above
To optimize a slow-running for loop in R, you can use strategies such as converting the loop to vectorized operations when possible, preallocating output objects to reduce memory reallocation, and minimizing unnecessary calculations or redundant checks inside the loop. These strategies can significantly improve the performance of the loop.

Can you find the minimum value in a matrix in R?

  • Yes, using the min() function
  • No, R does not support finding the minimum value in a matrix
  • Yes, but it requires writing a custom function
  • Yes, using the minimum() function
Yes, you can find the minimum value in a matrix in R using the min() function. The min() function returns the smallest value in the matrix, considering all its elements.

In R, a basic pie chart is created using the ______ function.

  • pie()
  • barplot()
  • plot()
  • scatterplot()
In R, a basic pie chart is created using the pie() function. It takes a vector of non-negative numeric values as input and creates a pie chart where each segment represents a proportion of the whole.

Can you describe a scenario where you would need to conduct a statistical test in R?

  • Comparing the means of two groups
  • Testing the independence of categorical variables
  • Determining the correlation between two variables
  • All of the above
All of the mentioned scenarios may require conducting a statistical test in R. Statistical tests are used to assess hypotheses, make inferences about populations, and analyze relationships between variables. Some common scenarios include comparing the means of two groups using t-tests, testing the independence of categorical variables using chi-square tests, and determining the correlation between two variables using correlation tests.

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