In R, the "..." (ellipsis) argument is used to pass additional _________ to a function.
- data
- functions
- operators
- parameters
The '...' (ellipsis) argument in R functions is used to denote a variable number of arguments. These arguments can be passed to other functions, providing flexibility in how functions are defined and used.
In R, the ________ function is used to concatenate vectors after converting to character.
- None of the above
- concat()
- merge()
- paste()
In R, the 'paste()' function is used to concatenate vectors element-wise after converting them to character. The result is a character vector. For example, 'paste(c("Hello", "Goodbye"), c("world!", "friends!"))' would return a vector containing "Hello world!" and "Goodbye friends!".
What are some limitations of R and how have you worked around them in your past projects?
- Difficulty in handling large datasets
- Fewer resources for learning
- Limited performance speed
- Not a general-purpose language
One of the well-known limitations of R is its difficulty in handling large datasets due to its in-memory limitations. However, this can be worked around using certain packages designed for large datasets (such as 'data.table' and 'ff'), optimizing the code, or using R in combination with a database system that can handle larger datasets, like SQL.
Suppose you have a vector of strings in R and you need to concatenate them into a single string. How would you do that?
- Use the combine() function
- Use the concat() function
- Use the merge() function
- Use the paste() function with collapse argument
In R, we can use the paste() function with the collapse argument to concatenate a vector of strings into a single string. For example, paste(c("Hello", "World"), collapse = " ") would return "Hello World".
To determine the number of characters in a string, you can use the ________ function in R.
- len()
- length()
- nchar()
- strlen()
In R, the nchar() function is used to determine the number of characters in a string. For example, nchar("Hello") would return 5.
What function is commonly used to create a basic scatter plot in R?
- scatterplot()
- plot()
- points()
- scatter()
The plot() function is commonly used to create a basic scatter plot in R. It can be used to visualize the relationship between two numeric variables by plotting the data points as individual points on the graph.
In R, a variable that contains a sequence of data is called a ________.
- DataFrame
- List
- Matrix
- Vector
A vector in R is a sequence of data elements of the same basic type. Members in a vector are officially called components. However, R also has other data structures like lists, matrix, and dataframe which can hold multiple data types or more complex data.
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.