How would you handle a situation where you need to remove escape sequences from a string in R?

  • Use the gsub() function with the appropriate pattern
  • Use the str_remove() function from the stringr package
  • Use the replace() function with the appropriate pattern
  • Use the sub() function with the appropriate pattern
To remove escape sequences from a string in R, you can use the gsub() function with the appropriate pattern. For example, if you want to remove all backslashes from a string, you can use gsub("\", "", my_string). This replaces every occurrence of backslashes with an empty string, effectively removing the escape sequences.

To assign a numeric value to a variable in R, you can use the syntax variable_name <- ________.

  • FALSE
  • "value"
  • TRUE
  • value
In R, to assign a numeric value to a variable, we use the syntax variable_name <- value. The left arrow (<-) is the assignment operator in R.

Imagine you need to calculate the median of each column in a data frame in R. How would you do this?

  • Use the apply() function with the appropriate margin argument and the median() function
  • Use the colMedian() function with the data frame as an argument
  • Use the median() function directly on the data frame
  • Use the median() function with the numeric columns specified by name
To calculate the median of each column in a data frame in R, you would use the apply() function with the appropriate margin argument (2 for columns) and the median() function. This allows you to apply the median() function to each column of the data frame.

Suppose you're given a data frame in R and asked to find the maximum or minimum value in each column or row. How would you do this?

  • Use the apply() function with the appropriate margin argument and the max() or min() function
  • Use the max.col() or min.col() function for data frames
  • Use the apply() function with the appropriate margin argument and the max_row() or min_row() function
  • Use the max() or min() function with the appropriate argument and the apply() function
To find the maximum or minimum value in each column or row of a data frame in R, you can use the apply() function with the appropriate margin argument (1 for rows, 2 for columns) and the max() or min() function. This combination allows you to apply the max() or min() function across the specified dimension and obtain the desired results.

To customize the markers in an R scatter plot, you would use the ______ parameter.

  • col
  • pch
  • cex
  • marker
To customize the markers in an R scatter plot, you would use the pch parameter. It allows you to specify a numerical value or character that represents the marker type for the data points, such as circles, squares, triangles, or custom symbols.

What is the purpose of a while loop in R?

  • To repeat a block of code as long as a certain condition is true
  • To iterate over a sequence of values
  • To execute a block of code a specific number of times
  • To break out of a loop when a condition is met
The purpose of a while loop in R is to repeat a block of code as long as a certain condition is true. The loop continues until the condition becomes false. This allows for repetitive execution of code based on a specific condition.

Suppose you have a variable with a value, and you want to change that value. How would you accomplish this?

  • By reassigning the variable with the new value
  • By using the update() function
  • None of the above
  • You can't change the value of a variable in R
To change the value of a variable in R, you simply reassign the variable with the new value using the assignment operator '<-'. For example, if 'x' is 5 and you want to change it to 10, you would use 'x <- 10'.

The function to generate random numbers in R following a normal distribution is ________.

  • generate_random()
  • randn()
  • random()
  • rnorm()
The rnorm() function in R is used to generate random numbers following a normal distribution. For example, rnorm(10) would generate 10 random numbers from a standard normal distribution.

Imagine you need to create a bar chart in R that color-codes bars based on a specific criteria. How would you do this?

  • Use the barplot() function and provide a vector of colors corresponding to each bar
  • Use the pie() function and provide a vector of colors corresponding to each segment
  • Use the plot() function and specify the colors parameter
  • Use the ggplot2 package and the geom_bar() function with the fill aesthetic
To create a bar chart in R that color-codes bars based on a specific criteria, you would use the barplot() function. Provide a vector of colors corresponding to each bar, ensuring that the colors align with the specific criteria you want to represent.

How does R handle operator precedence when both 'AND' and 'OR' are used in a single expression?

  • R follows the standard operator precedence, where 'AND' takes precedence over 'OR'
  • R follows the standard operator precedence, where 'OR' takes precedence over 'AND'
  • R gives equal precedence to 'AND' and 'OR', evaluating them left to right
  • The precedence depends on the context and cannot be determined
When both 'AND' and 'OR' operators are used in a single expression, R follows the standard operator precedence rules. The 'AND' operator ('&') takes precedence over the 'OR' operator ('