What techniques can be used in R to visualize high-dimensional data?

  • Scatter plots with color or size encoding
  • Parallel coordinate plots
  • Dimensionality reduction techniques like PCA or t-SNE
  • All of the above
All of the mentioned techniques can be used in R to visualize high-dimensional data. Scatter plots can encode additional dimensions through color or size. Parallel coordinate plots can show relationships between multiple variables. Dimensionality reduction techniques like PCA or t-SNE can project high-dimensional data into lower dimensions for visualization.

Suppose you're asked to write a function in R that uses a global variable. How would you do it?

  • Define the global variable outside of the function and access it within the function
  • Define the global variable inside the function and mark it as global using the global() function
  • Define the global variable inside the function and use the global_var() keyword
  • None of the above
To write a function in R that uses a global variable, you would define the global variable outside of the function and access it within the function. Since global variables are accessible from anywhere in the program, the function can directly reference and modify the global variable as needed.

Imagine you need to create a function in R that checks if a number is prime. How would you do this?

  • is_prime <- function(n) { if (n <= 1) { return(FALSE) } for (i in 2:sqrt(n)) { if (n %% i == 0) { return(FALSE) } } return(TRUE) }
  • is_prime <- function(n) { if (n <= 1) { return(TRUE) } for (i in 2:sqrt(n)) { if (n %% i == 0) { return(TRUE) } } return(FALSE) }
  • is_prime <- function(n) { if (n <= 1) { return(FALSE) } for (i in 2:sqrt(n)) { if (n %% i != 0) { return(TRUE) } } return(FALSE) }
  • All of the above
To create a function in R that checks if a number is prime, you can use the following code: is_prime <- function(n) { if (n <= 1) { return(FALSE) } for (i in 2:sqrt(n)) { if (n %% i == 0) { return(FALSE) } } return(TRUE) }. The function takes a number n as input and iterates from 2 to the square root of n, checking if any of these numbers divides n. If a divisor is found, the function returns FALSE; otherwise, it returns TRUE.

Can you describe a situation where you would need to use logical operations in R?

  • Checking conditions in control flow statements
  • Filtering data based on specific criteria
  • Creating boolean variables for flagging
  • All of the above
Logical operations in R are commonly used in situations such as checking conditions in control flow statements, filtering data based on specific criteria, and creating boolean variables for flagging or indicating certain conditions.

In R, the operator != is used to check if two values are ________.

  • equal
  • not equal
  • less than
  • greater than
In R, the operator != is used to check if two values are not equal. For example, 3 != 4 would return TRUE.

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.

Can you describe a scenario where you would need to use a nested if statement in R?

  • When you have multiple conditions to evaluate and perform different actions based on each condition
  • When you want to optimize performance by avoiding multiple if statements
  • When you need to perform complex calculations with multiple if statements
  • All of the above
A scenario where you would need to use a nested if statement in R is when you have multiple conditions to evaluate and need to perform different actions based on each condition. Nested if statements allow for more complex branching logic and the ability to handle intricate sets of conditions.

Can you discuss how scoping rules apply in R functions?

  • R follows lexical scoping, where functions can access objects in their enclosing environment
  • R follows dynamic scoping, where functions can access objects in their calling environment
  • R follows global scoping, where functions can access objects outside their environment
  • R follows local scoping, where functions can only access objects within their own environment
In R, scoping rules follow lexical scoping, also known as static scoping. This means that functions can access objects in their enclosing environment, including objects defined outside the function but within the parent environment. This allows functions to access variables defined in higher-level environments.