What function in R is used to calculate the square root of a number?

  • root()
  • sqr()
  • sqrt()
  • squareroot()
The sqrt() function in R is used to calculate the square root of a number. For example, sqrt(4) would return 2.

How would you calculate a running median in R?

  • Use the runMedian() function from the caTools package
  • Use the rollapply() function from the zoo package
  • Use the cummedian() function from the stats package
  • Use the median() function with a sliding window approach
To calculate a running median in R, you can use the rollapply() function from the zoo package. The rollapply() function allows you to specify a window size and apply a function (such as median()) to a rolling window of values. This can be useful for analyzing time series or other sequential data.

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.

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.