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.

What are the methods to replace a certain pattern in a string in R?

  • Both 2 and 3
  • Use the gsub() function
  • Use the replace() function
  • Use the str_replace() function
In R, we can use the gsub() function from base R or the str_replace() function from the stringr package to replace a certain pattern in a string. For example, gsub("a", "b", "banana") or str_replace("banana", "a", "b") would replace all occurrences of "a" with "b" in the string "banana".

The ________ function is used to paste together strings, which can then be printed using the print() function.

  • combine()
  • glue()
  • paste()
  • str_c()
The paste() function in R can be used to concatenate strings. The result can then be printed using the print() function. For example, print(paste("Hello", "world")) will output "Hello world".

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 ('

The R function to calculate the factorial of a number is ________.

  • fact()
  • factorial()
  • multiplication()
  • product()
The factorial() function in R is used to calculate the factorial of a number. For example, factorial(5) would return 120 because 5 factorial (5!) is 54321 = 120.

What are some strategies for handling non-normal data in statistical analyses in R?

  • Transforming the data
  • Using non-parametric tests
  • Employing robust statistical methods
  • All of the above
All of the mentioned strategies can be used for handling non-normal data in statistical analyses in R. Transforming the data (e.g., logarithmic or power transformations) can make it conform to normality assumptions. Non-parametric tests, which do not rely on specific distribution assumptions, can be used instead of parametric tests. Robust statistical methods are designed to be less sensitive to deviations from normality and can provide more reliable results in such cases. The choice of strategy depends on the characteristics of the data and the research question.

Imagine you need to calculate the average of all the numbers in a list using a for loop in R. How would you do this?

  • total <- 0; count <- 0; for (num in list) { total <- total + num; count <- count + 1 }; average <- total / count;
  • average <- 0; for (num in list) { average <- average + num / length(list) }
  • average <- 0; count <- 0; for (num in list) { average <- (average * count + num) / (count + 1); count <- count + 1 }
  • average <- sum(list) / length(list)
To calculate the average of all the numbers in a list using a for loop, you can initialize variables total and count to 0. Then, iterate over each number in the list, updating total by adding the current number and incrementing count by 1. Finally, calculate the average by dividing total by count.

A ________ is a special type of vector in R that can contain elements of different classes.

  • Character Vector
  • List
  • Logical Vector
  • Numeric Vector
A list in R, though similar in some ways to a vector, can contain elements of different classes - numbers, characters, vectors, and even other lists.

To filter rows in a data frame in R based on a condition, you would use the ______ function.

  • filter()
  • subset()
  • select()
  • extract()
To filter rows in a data frame in R based on a condition, you would use the filter() function. The filter() function allows you to specify a condition or logical expression to select rows that meet the specified criteria, creating a subset of the data frame.