Suppose you're working with a dataset in R and you want to check the data type of a certain variable. How would you do it?

  • Either of the above
  • None of the above
  • Use the class() function
  • Use the typeof() function
Both typeof() and class() functions in R can be used to check the data type of a variable. While typeof() returns the internal storage mode, class() returns the attributes of the object as how it should be treated in context of object-oriented programming.

In R, the _________ function is used to print the output.

  • echo()
  • output()
  • print()
  • show()
The 'print()' function is used in R to print the output to the console. This can be used to display the value of a variable, a message, or the output of a function.

Which data type in R is used to store true/false values?

  • Boolean
  • Character
  • Logical
  • Numeric
In R, true/false values are stored as logical data type. This data type only has two possible values: TRUE and FALSE.

In R, to prematurely exit a while loop, you can use the ______ keyword.

  • break
  • stop
  • exit
  • quit
In R, to prematurely exit a while loop, you can use the 'break' keyword. When the 'break' statement is encountered within the loop's code block, it immediately terminates the loop execution, and the program continues with the next statement after the loop. This allows for early termination of the loop based on certain conditions.

In R, if a variable is not found in the local environment of a nested function, the function will look in the ________ of the outer function.

  • Parent environment
  • Global environment
  • Child environment
  • Current environment
In R, if a variable is not found in the local environment of a nested function, the function will look in the parent environment of the outer function. This allows the nested function to access variables defined in the outer function, providing access to variables from higher-level environments.

In R, the ______ function can be used to find the maximum value in each column of a data frame.

  • apply()
  • max.col()
  • colMax()
  • max()
In R, the max.col() function can be used to find the maximum value in each column of a data frame. The max.col() function returns a vector of indices corresponding to the column-wise maximum values.

Imagine you're working with a numeric vector in R that contains multiple modes. How would you handle this situation?

  • Report all the modes as a vector
  • Report the first mode encountered
  • Report the mode with the highest frequency
  • Report an error indicating multiple modes
When dealing with a numeric vector in R that contains multiple modes, you would handle this situation by reporting all the modes as a vector. This ensures that all the modes with equal frequency are included in the result.

Suppose you're asked to write a function in R that takes a list of numbers and returns a new list containing only the even numbers. How would you do it?

  • Use lapply() to iterate over the list and filter out the even numbers
  • Use a for loop to iterate over each element and filter out the even numbers
  • Use the filter() function to extract the even numbers
  • Use the subset() function with a logical condition to filter the even numbers
To write a function in R that takes a list of numbers and returns a new list containing only the even numbers, you can use lapply() to iterate over the list and apply a filtering condition. Inside the lapply() function, you can use a logical condition to filter out the even numbers. The result will be a new list containing only the desired elements.

Describe a situation where you had to use a global variable in R for a complex task. What were some of the challenges you faced, and how did you overcome them?

  • Handling shared data between multiple functions or modules
  • Ensuring proper synchronization and consistency
  • Managing dependencies and potential conflicts
  • All of the above
One situation where you might need to use a global variable in R for a complex task is when handling shared data between multiple functions or modules. Challenges in such scenarios may include ensuring proper synchronization and consistency of the global variable's state, managing dependencies between functions that rely on the global variable, and mitigating potential conflicts or unintended modifications to the global variable. Overcoming these challenges often involves careful design, documentation, and testing of the code to ensure the correct usage and behavior of the global variable.

Imagine you're asked to optimize a slow-running function in R. What are some strategies you could use to improve its performance?

  • Vectorize operations
  • Use efficient data structures
  • Minimize unnecessary calculations
  • All of the above
To optimize a slow-running function in R, you can use strategies such as vectorizing operations, using efficient data structures (e.g., matrices instead of data frames), minimizing unnecessary calculations (e.g., precomputing values outside loops), avoiding repeated function calls or redundant checks, and utilizing R's built-in functions or packages optimized for specific tasks. These strategies can significantly improve the performance of the function.