Imagine you need to determine the data type of a variable in R. How would you do this?

  • Use the mode() function on the variable
  • Use the typeof() function on the variable
  • Use the class() function on the variable
  • Use the str() function on the variable
To determine the data type of a variable in R, you would use the typeof() function on the variable. The typeof() function returns a character string representing the data type of the object.

Can you discuss the advantages and disadvantages of base R plotting versus ggplot2?

  • Base R plotting is more flexible, but ggplot2 provides a more structured grammar of graphics
  • Base R plotting has a steeper learning curve, but ggplot2 is easier to learn
  • Base R plotting is faster, but ggplot2 produces more visually appealing plots
  • Base R plotting has limited plotting options, but ggplot2 is highly customizable
Base R plotting offers more flexibility, allowing for a wider range of customization and plot types. However, ggplot2 provides a more structured and consistent grammar of graphics, making it easier to create complex plots. The choice between the two often depends on personal preference and the specific requirements of the plot.

Imagine you have a string in R and you want to convert it to uppercase. How would you do this?

  • Use the to_upper() function
  • Use the toupper() function
  • Use the upper() function
  • Use the uppercase() function
In R, the toupper() function is used to convert a string to uppercase. For example, toupper("Hello") would return "HELLO".

Can a global variable in R be accessed from within a function?

  • Yes, a global variable can be accessed from within a function
  • No, global variables are only accessible outside of functions
  • It depends on the scoping rules applied within the function
  • None of the above
Yes, a global variable in R can be accessed from within a function. The scoping rules in R allow functions to access variables defined in the global environment. However, if a variable with the same name is defined within the function's local environment, it will take precedence over the global variable.

The concept of performing operations on entire vectors at once, without the need for looping over individual elements, is known as ______ in R.

  • vectorization
  • looping
  • indexing
  • recursion
The concept of performing operations on entire vectors at once, without the need for looping over individual elements, is known as vectorization in R. It leverages optimized internal functions in R to apply operations to entire vectors efficiently, resulting in concise and computationally efficient code.

Suppose you're asked to create a scatter plot in R that shows the relationship between two numeric variables in a data set. How would you do it?

  • Use the plot() function and specify the two numeric variables as the x and y arguments
  • Use the scatterplot() function and specify the two numeric variables as the x and y arguments
  • Use the points() function and specify the two numeric variables as the x and y arguments
  • Use the ggplot2 package and the geom_point() function with the two numeric variables as the x and y aesthetics
To create a scatter plot in R that shows the relationship between two numeric variables in a data set, you would use the plot() function. Specify the two numeric variables as the x and y arguments in the function call, and R will generate the scatter plot with the corresponding data points.

What are some of the key statistical functions in R for mathematical computations?

  • All of the above
  • mean(), median(), and mode()
  • min(), max(), and sum()
  • sd(), var(), and cor()
R provides a wide range of statistical functions for mathematical computations. This includes functions to calculate the mean(), median(), mode(), minimum (min()), maximum (max()), sum(), standard deviation (sd()), variance (var()), correlation (cor()), and many others.

How does the efficiency of a for loop in R compare to vectorized operations?

  • For loops are generally slower than vectorized operations
  • For loops are generally faster than vectorized operations
  • For loops have the same efficiency as vectorized operations
  • Efficiency depends on the complexity of the code inside the loop
For loops are generally slower than vectorized operations in R. R is optimized for vectorized operations, which can perform operations on entire vectors or matrices at once, leading to more efficient and faster execution.

How would you customize the appearance of an R scatter plot, including changing colors, markers, and sizes?

  • By using the col, pch, and cex parameters in the plot() function
  • By using the legend() function
  • By using the theme() function from the ggplot2 package
  • By using the par() function and graphical parameters
To customize the appearance of an R scatter plot, including changing colors, markers, and sizes, you can use the col parameter to change colors, the pch parameter to change markers, and the cex parameter to change the size of the points. These graphical parameters can be specified within the plot() function.

How can you handle situations where your calculations result in 'Inf' or 'NaN'?

  • Both of these methods
  • None of the above
  • Use ifelse() function to handle such situations
  • Use is.finite() function to check the result
One way to handle this is by using the is.finite() function which checks whether the value is finite or not. This function returns FALSE if the value is Inf or NaN and TRUE otherwise. Depending on the use case, you can then decide how to handle these non-finite values.