The syntax as.character(number) in R is used to convert a ________ to a string.

  • all of the above
  • double
  • integer
  • numeric
In R, the as.character() function is used to convert numeric data (which includes integers, doubles, etc.) to a string. For example, as.character(123) would return "123".

In R, the boolean values are represented as ________ and ________.

  • TRUE and FALSE
  • 1 and 0
  • T and F
  • Y and N
In R, the boolean values are represented as TRUE and FALSE. These are the reserved keywords in R for representing logical true and false values, respectively.

In R, the ______ function can be used to get a summary of the data in a data frame.

  • summary()
  • describe()
  • stats()
  • overview()
The summary() function in R can be used to obtain a summary of the data in a data frame. It provides information such as minimum, maximum, median, mean, and quartiles for each column in the data frame.

How do you determine the length of a string in R?

  • len()
  • length()
  • nchar()
  • strlen()
In R, the nchar() function is used to determine the length of a string. For example, nchar("Hello") would return 5.

A comment in R starts with the symbol _________.

  • #
  • ##
  • --
  • //
In R, the '#' symbol is used to denote a comment. Any text following this symbol on a line is ignored by the R interpreter. This is a useful way to annotate your code.

Imagine you have a dataset with a column of grades ('A', 'B', 'C', 'D', 'F') and you want to add a column that indicates if the grade is 'pass' or 'fail'. How would you do this using a nested if statement in R?

  • ifelse(grades %in% c('A', 'B', 'C'), 'pass', 'fail')
  • if (grades %in% c('A', 'B', 'C')) { 'pass' } else { 'fail' }
  • if (grades == 'A') { 'pass' } elseif (grades == 'B') { 'pass' } elseif (grades == 'C') { 'pass' } else { 'fail' }
  • All of the above
To add a column indicating if a grade is 'pass' or 'fail' using a nested if statement in R, you can use the following structure: if (grades == 'A') { 'pass' } elseif (grades == 'B') { 'pass' } elseif (grades == 'C') { 'pass' } else { 'fail' }. This nested if statement checks each grade condition sequentially and assigns the corresponding pass or fail outcome.

What are some primary uses of the R programming language?

  • Data Cleaning
  • Machine Learning
  • Statistical Analysis
  • Web Development
While R can be used for data cleaning and machine learning, its primary focus and strength lie in statistical analysis. It provides an extensive array of libraries and tools for statistical modeling. However, it's less commonly used for web development, which is usually handled by languages like JavaScript, Python, Ruby, etc.

Can you calculate the median of a matrix in R?

  • Yes, using the apply() function
  • No, R does not support calculating the median of a matrix
  • Yes, but it requires writing a custom function
  • Yes, using the median() function directly
Yes, you can calculate the median of a matrix in R using the apply() function. By specifying the appropriate margin argument (1 for rows, 2 for columns), you can apply the median() function across the specified dimension to calculate the median values.

Suppose you're asked to write a function in R that takes a data frame and returns a new data frame with only numeric columns. How would you do it?

  • Use the select() function from the dplyr package
  • Use the filter() function from the dplyr package
  • Use the subset() function
  • Use the keep() function from the purrr package
To accomplish this task, you can use the select() function from the dplyr package in R. You can specify the column selection criteria to include only numeric columns and obtain a new data frame with the desired columns.

Suppose you're writing a function in R to handle a complex set of conditions. How would you approach this to avoid deep nesting of if statements?

  • Break down the conditions into smaller functions or helper variables
  • Utilize switch() or case_when() functions for handling multiple conditions
  • Use logical operators and vectorization for efficient conditional operations
  • All of the above
To avoid deep nesting of if statements when writing a function in R to handle complex conditions, you can employ various approaches. This includes breaking down the conditions into smaller functions or helper variables, utilizing functions like switch() or case_when() to handle multiple conditions concisely, and leveraging logical operators and vectorization for efficient conditional operations. These approaches help enhance code readability, maintainability, and performance.