How do you check if a value is a number in R?

  • Use is.character() function
  • Use is.integer() function
  • Use is.logical() function
  • Use is.numeric() function
The is.numeric() function in R is used to check if a value or a vector is numeric. It returns TRUE if the value is numeric and FALSE otherwise.

Describe a situation where you had to use escape characters in a regular expression in R. How did you manage it?

  • When matching a string pattern that contains special characters
  • When removing specific characters from a string
  • When replacing a certain pattern with another in a string
  • All of the above
One situation where escape characters are commonly used in regular expressions in R is when matching a string pattern that contains special characters. For example, to match a literal dot (.) or parentheses in a regular expression, you need to escape them with a backslash: .. Another situation is when removing or replacing specific characters in a string using regular expressions. To manage this, I used the appropriate escape sequences to ensure the desired pattern matching or manipulation.

Imagine you need to create a scatter plot in R that color-codes points based on a third categorical variable. How would you do this?

  • Use the col or col.fill parameter in the plot() function and map the third categorical variable to colors
  • Use the scatterplot() function and specify the third categorical variable as the col or color argument
  • Use the points() function and manually assign colors based on the third categorical variable
  • Use the ggplot2 package and the geom_point() function with the third categorical variable as the color aesthetic
To color-code points in a scatter plot based on a third categorical variable in R, you would use the col or col.fill parameter in the plot() function. Map the third categorical variable to different colors, and R will assign the corresponding colors to the data points on the scatter plot.

If a matrix in R is created with elements of different data types, R will ______.

  • coerce the elements to the most flexible type
  • retain the individual data types of the elements
  • throw an error
  • None of the above
If a matrix in R is created with elements of different data types, R will coerce the elements to the most flexible type. The most flexible type refers to the type that can accommodate all the values in the matrix. This ensures that all elements of the matrix are of the same data type for consistent operations.

What are the differences between the '==' and '===' operators in R?

  • There is no '===' operator in R
  • '==' checks for equality of values, while '===' checks for equality of values and types
  • '==' and '===' are used interchangeably in R
  • '===' checks for equality of values, while '==' checks for equality of values and types
In R, there is no '===' operator. The '==' operator checks for equality of values, disregarding the types of the compared objects. It returns TRUE if the values are equal and FALSE otherwise.

Can you discuss how R determines the max or min of a character vector?

  • R determines the max or min of a character vector based on lexicographic order
  • R converts character values to numeric values and finds the max or min numerically
  • R returns an error when trying to find the max or min of a character vector
  • R treats character values as factors and finds the max or min based on the factor levels
R determines the max or min of a character vector based on lexicographic order. It compares the characters based on their ASCII values, considering factors such as uppercase and lowercase letters and special characters.

What is the basic function used to print output in R?

  • echo()
  • output()
  • print()
  • show()
The 'print()' function is the basic function used to display the output in R. It prints its argument and returns it invisibly. This is useful for displaying the results of computations or the values of variables.

In R, the ______ function can be used to apply a function to each element of a list.

  • lapply()
  • sapply()
  • mapply()
  • apply()
In R, the lapply() function can be used to apply a function to each element of a list. It returns a new list where the specified function has been applied to each element of the input list. The lapply() function is particularly useful for performing operations or calculations on each element of a list in a concise and efficient manner.

Suppose you're working with a large and complex list in R. How would you print it in a way that's easy for a human to understand?

  • None of the above
  • Use the cat() function with the "n" separator
  • Use the print() function with the max.levels argument
  • Use the str() function
The str() function in R provides a compact, human-readable description of any R data structure, which makes it easier to understand the structure and content of large and complex lists. It displays the internal structure of an R object in a way that's compact and informative.

The ______ function in R can be used to merge two data frames by common columns or row names.

  • rbind()
  • cbind()
  • merge()
  • join()
The merge() function in R can be used to merge two data frames based on common columns or row names. It provides flexible options for specifying the merging criteria and can handle various types of joins such as inner join, left join, right join, and outer join.