250+ TOP MCQs on Regular Expressions and Text Variables and Answers

Data Science Multiple Choice Questions on “Regular Expressions and Text Variables”.

1. Which of the following function is good for the automatic splitting of names?
a) split
b) strsplit
c) autsplit
d) none of the mentioned

Answer: b
Explanation: strsplit split a character string or vector of character strings using a regular expression or a literal string.

2. Point out the correct statement.
a) gsub is used for fixing character vectors
b) sub is used for finding values like grep
c) grep is used for fixing character vectors
d) none of the mentioned

Answer: a
Explanation: sub and gsub is used for fixing character vectors.

3. Which of the following function is used for fixing character vectors?
a) tolower
b) toUPPER
c) toLOWER
d) all of the mentioned

Answer: a
Explanation: It translates character to lowercase.

4. Which of the following metacharacter is used to refer to any character?
a) %
b) @
c) .
d) All of the mentioned

Answer: c
Explanation: A dot in function name can mean any of the following: nothing at all; a separator between method and class in S3 method.

5. Point out the wrong statement.
a) Variables with character values should be made less descriptive
b) Variables with character values should usually be made into factor variable
c) Common variables are used to apply transforms
d) All of the mentioned

Answer: a
Explanation: Variables with character values should be made more descriptive.

6. Which of the following is used for specifying character class with metacharacter?
a) []
b) {}
c) /+
d) All of the mentioned

Answer: a
Explanation: You can list set of characters to accept a given point in the match.

7. Regular expressions can be thought of as a combination of literals and metacharacters.
a) True
b) False

Answer: a
Explanation: Regular expressions have rich set of metacharacters.

8. Which of the following signs are used to indicate repetition?
a) #
b) *
c) –
d) All of the mentioned

Answer: b
Explanation: * and + are metacharacters for repetition of data.

9. Which of the following function is used for searching text strings by means of regular expression?
a) grepd
b) grepl
c) gepexpr
d) all of the mentioned

Answer: b
Explanation: grep, grepl, regexpr, gregexpr and regexec search for matches to argument pattern within each element of a character vector.

10. merge function is used for merging data frames.
a) True
b) False

Answer: a
Explanation: To merge two data frames horizontally, use the merge function.

Leave a Reply

Your email address will not be published. Required fields are marked *