What is the purpose of the main parameter in the R plotting function?

  • To set the color of the plot
  • To add a legend to the plot
  • To specify the main title of the plot
  • To control the axis labels
The main parameter in the R plotting function is used to specify the main title of the plot. It allows you to provide a descriptive title that summarizes the content or purpose of the plot.

How do you structure an if-else statement in R?

  • if (condition) { code to execute if condition is true } else { code to execute if condition is false }
  • if (condition) { code to execute if condition is true } elseif (condition) { code to execute if another condition is true } else { code to execute if all conditions are false }
  • if (condition) { code to execute if condition is true } else (condition) { code to execute if condition is false }
  • if (condition) { code to execute if condition is true }
In R, an if-else statement is structured using the if keyword, followed by the condition inside parentheses. The code to execute if the condition is true is enclosed in curly braces after the if statement. The else keyword is followed by the code to execute if the condition is false, also enclosed in curly braces.

How would you handle a situation where you need to check multiple conditions in R and perform different operations based on each one?

  • Use nested if statements to evaluate each condition separately
  • Use the ifelse() function with multiple conditions and corresponding outcomes
  • Use the switch() function to handle multiple conditions
  • Use the apply family of functions for iteration over conditions
To handle a situation where you need to check multiple conditions in R and perform different operations based on each one, you can use the ifelse() function with multiple conditions and corresponding outcomes. This allows you to perform efficient vectorized operations and get the desired outcome based on each condition.

If you're using a while loop in R to iterate over a vector, you must manually increment the index variable with each loop. The increment operation in R is written as ______.

  • index++
  • index--
  • index = index + 1
  • index = index - 1
If you're using a while loop in R to iterate over a vector, you must manually increment the index variable with each loop. In R, the increment operation is written as 'index = index + 1'. This statement updates the value of the index variable by adding 1 to it. By incrementing the index within the loop, you can iterate through the elements of a vector.

How can you format the print output in R, such as limiting decimal points or adding padding?

  • None of the above
  • Use the format() function
  • Use the round() function to limit decimal points and the str_pad() function to add padding
  • You cannot format the print output in R
The 'format()' function in R can be used to format the print output. This includes controlling the number of decimal places, adding padding, setting field widths, and more. For example, 'format(round(x, 2))' would round 'x' to 2 decimal places.

A variable that is defined in the global environment in R and can be accessed from anywhere in your program is a ________.

  • Global variable
  • Local variable
  • Constant variable
  • System variable
A variable that is defined in the global environment in R and can be accessed from anywhere in the program is called a global variable. Global variables are not confined to any specific function or scope and can be accessed and modified throughout the program.

The ______ function in R can be used to calculate the standard deviation of a numeric vector.

  • sd()
  • var()
  • mean()
  • median()
The sd() function in R can be used to calculate the standard deviation of a numeric vector. The sd() function computes the sample standard deviation, which measures the spread or variability of the values in the vector.

The ______ function in R can be used to add text annotations to a scatter plot.

  • text()
  • annotate()
  • label()
  • add_text()
The text() function in R can be used to add text annotations to a scatter plot. It allows you to specify the coordinates and the text to be displayed at those coordinates, providing additional information or labels within the plot.

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.