If a variable with the same name exists in both the local and global environment in R, the ______ variable will be used.
- Local
- Global
- R will throw an error
- Both local and global variables will be used simultaneously
If a variable with the same name exists in both the local and global environment in R, the local variable will be used. R follows the scoping rules where variables defined in the local environment take precedence over variables with the same name in the global environment.
To calculate the square of a number in R, you can use the ^ operator, like number ^ ________.
- 1
- 2
- 2-Jan
- 3
To square a number in R, you use the ^ operator with 2 as the exponent. For example, to calculate the square of 4, you would use 4^2, which would return 16.
To extract a specific substring from a string in R, you can use the ________ function.
- extract()
- get()
- sub()
- substr()
The substr() function in R is used to extract a specific substring from a string. For example, substr("Hello", 2, 3) would return "el".
Suppose you have two character vectors and you need to concatenate corresponding elements from each vector with a hyphen in between. How would you do it?
- None of the above
- Using the c() function with sep = "-"
- Using the paste() function with sep = "-"
- Using the paste0() function with "-"
If you have two character vectors in R, you can concatenate corresponding elements from each vector with a hyphen in between using the 'paste()' function with 'sep = "-"'. For example, 'paste(c("Hello", "Goodbye"), c("world!", "friends!"), sep = "-")' would return a vector containing "Hello-world!" and "Goodbye-friends!".
What is the result of the logical operation 'TRUE OR FALSE' in R?
- TRUE
- FALSE
- Error
The result of the logical operation 'TRUE OR FALSE' in R is TRUE. The 'OR' operation returns TRUE if at least one of the operands is TRUE.
Suppose you're developing a package in R. How would you handle errors in your functions to ensure that users of your package get informative error messages?
- Use meaningful error messages in functions
- Handle specific errors with tryCatch()
- Provide clear documentation on expected input and potential errors
- All of the above
When developing a package in R, you can handle errors in your functions to ensure that users of your package get informative error messages by using meaningful error messages within the functions, handling specific errors with tryCatch(), and providing clear documentation on expected input and potential errors. These practices help users understand and troubleshoot issues more effectively.
Variables in R are ________ sensitive.
- Case
- None of the above
- Time
- Value
Variable names in R are case sensitive, which means that 'myVariable', 'myvariable', and 'MYVARIABLE' would all be treated as different variables. It's crucial to be consistent with capitalization when naming and referencing variables in R.
What function is commonly used to calculate the mean in R?
- mean()
- median()
- sd()
- var()
The mean() function is commonly used to calculate the mean (average) of a numeric vector in R. It returns the arithmetic mean of the values.
Recursive functions in R can be used to solve problems that have a ________ structure.
- Recursive
- Iterative
- Sequential
- Self-similar
Recursive functions in R can be used to solve problems that have a self-similar structure. These are problems where a solution to a larger instance of the problem can be obtained by combining solutions to smaller instances of the same problem. The recursive function breaks down the problem into smaller sub-problems, solving them recursively until a base case is reached. This self-similar structure allows for the application of recursion to efficiently solve the problem.
In R, the ______ function can be used to compute the determinant of a matrix.
- determinant()
- det()
- eigen()
- svd()
In R, the det() function can be used to compute the determinant of a matrix. The det() function takes a matrix as its argument and returns its determinant. The determinant is a value that provides information about the invertibility and properties of the matrix.