R Programming Questions and Answers Part-20

1. Columns can be arranged in descending order too by using the special ____ operator.
a) asc()
b) desc()
c) descending()
d) subset

Answer: b
Explanation: This will sort the order in decreasing order.

2. Point out the wrong statement?
a) Renaming a variable in a data frame in R is surprisingly hard to do
b) The mutate() function exists to compute transformations of variables in a data frame
c) mute() function, which does the same thing as mutate() but then drops all non-transformed variables
d) The data frame is a key data structure in statistics and in R

Answer: c
Explanation: The rename() function is designed to make this process easier.

3. dplyr can be integrated with the ________ package for large fast tables.
a) data.table
b) read.table
c) data.data
d) table.read

Answer: a
Explanation: The dplyr package is handy way to both simplify and speed up your data frame management code.

4. Which of the following function is similar to summarize?
a) arrange_by()
b) group()
c) group_by()
d) arrange

Answer: c
Explanation: The dplyr package provides a concise set of operations for managing data frames.

5. Point out the correct statement?
a) Blocks are evaluated until a new line is entered after the closing brace
b) Single statements are evaluated when a new line is typed at the start of the syntactically complete statement
c) The if/else statement conditionally evaluates two statements
d) Break will execute a loop while a condition is true

Answer: c
Explanation: The if/else statement returns, as its value, the value of the statement that was selected.

6. Which of the following R syntax is correct for while loop?
a) while ( statement1 ) statement2
b) while ( statement1 ) else statement2
c) while ( statement1 ) do statement2
d) while ( statement2 ) doelse statement2

Answer: a
Explanation: The while statement is very similar to the repeat statement.

7. Point out the wrong statement?
a) for will execute a loop a fixed number of times
b) break will execute a loop while a condition is true
c) if and else tests a condition and acting on it
d) break is used to break the execution of a loop

Answer: b
Explanation: The if-else structure allows you to test a condition and act on it depending on whether it’s true or false.

8. _______ is used to break the execution of a loop.
a) next
b) skip
c) break
d) delete

Answer: c
Explanation: Control structures allow you to respond to inputs or to features of the data and execute different R expressions accordingly.

9. Which of the following statement can be used to explicitly control looping?
a) if
b) while
c) break
d) for

Answer: c
Explanation: The break statement causes an exit from the innermost loop that is currently being executed.

10. Which of the following should be preferred for evaluation from list of alternatives?
a) subsett
b) eval
c) switch
d) set

Answer: b
Explanation: eval(x[[condition]]) is the best way to select one for evaluation.