# Multiple Choice Question for Basics of R

• By
• January 2, 2020
• Data Science

# Multiple Choice Question for Basics of R

Today we will go through multiple choice question for basics of R.

R is the open source scripting language used for statistical computing and the building of graphs.

It provides various facilities like data manipulation, calculation and graphical display.

Why is it named as R?

It is the initial of first two authors Robert Gentleman and Ross Ihaka.

IDE’s used in R

RStudio, Microsoft R Tools for Visual Studio, R Analytic Flow, TinnR, Jupyter. All of these are free software.

R is used widely for analysis. Many of the software and visualization tools are having plugins for R like eclipse, Tableau.

CRAN: Comprehensive R Archive Network is collection of sites which carry identical material, consisting of R distribution(s).

• What is the function can be used convert data into list format?
1. lapply()
2. list()
3. list()
4. both b and c

ANS:-B

• table() is used for
1. to convert data into data frame
2. to convert data frame into database table format
3. to find out categorical data with count
4. none of the above

ANS:-C

• Which of the following is valid for checking categorical variable?
1. Level
2. Table
3. Unique
4. All of the above

ANS:-D

• Suppose ABC is the matrix of 3 rows and 2 columns. Choose correct option(s) to rename columns:
1. Column_names(ABC)= c(“col1”,”col2”,”col3”)
2. colnames(ABC)=c(“col1”,”col2”)
3. columns(ABC)=c(“col1”,”col2”)
4. colnames(ABC)=c(“col1”,”col2”,”col3”)

ANS:- B

• Suppose ABC is the matrix of 3 rows and 4 columns. Choose correct option(s) to rename columns:
1. row_names(ABC)= c(“row1”,”row2”,”row3”)
2. rownames(ABC)=c(“row1”,”row2”)
3. row(ABC)=c(“row1”,”row2”)
4. rownames(ABC)=c(“row”,”row2”,”row3”)

ANS:- D

• Arrange in proper order of data type:
1. Logical, integer, numeric, character
2. Integer, numeric, character, logical
3. Character, logical, integer, numeric
4. Numeric, integer, character, logical

ANS:- A

• What is the output of below code:

A=10

B=20

print(A,B)

1. 10 20
2. Error
3. (10, 20)
4. None of the above

ANS: B

• State if True or False:

Return statement is compulsory while writing function in R

1. True
2. False

ANS: False

• State if True or False:

Last variable in function is by default return variable in R

1. True
2. False

ANS: True

• What package is need to be install for reading

ANS: B

• what is the output of below mentioned code?

logic1=c(T,F,F,T,F,T)

print(which (logic))

1. 1 4  6
2. 2 3  6
3. 6 4  1
4. 1 2  3

ANS: A

• What will be a, if a = seq (100,to = 1000, by = 20)
1. [100, 200, 400, …., 1000]
2. [100, 120, 140, …., 980, 1000]
3. [20, 120 ,220, …., 1000 ]
4. None of the above

ANS: B

• If A = c (1, 13, 42, 13, 4)  then what is A = A [ -4 ]?
1. 1, 13, 42, 4
2. 1, 13, 42, 13
3. 13
4. 1, 42, 13, 4

ANS: A

• name = “Navin, Mr. Naresh J”

what function can be used to split the string?

Output will be : “Navin”      “Mr. Naresh J”

1. strsplit(name,”[.]”)
2. charsplit(name,”[,]”)
3. stringsplit(name)
4. strsplit(name,”[,]”)

ANS: D

• i=100 , how to find out data type of i
1. type(i)
2. type(i)
3. class(i)
4. none of the above

ANS: C

• Which of the following is true:
4. both a and c

ANS: C

• If B is the data frame, how can we find out columns wise null values?
1. colSums ( is.na ( B ) )
2. null ( B ).sum
3. na ( B )
4. Both a and c

ANS: A

• What is the function used to find current date in R?
1. Sysdate()
2. Date()
3. Now()
4. All of the above

ANS: B

• Dt = “01-12-2020” is in the form of character. What is the option to convert date into “MM-DD-YYYY”
1. To_date (dt, ”MM – DD – YYYY”)
2. date( x = dt, format = “%m / %d / %Y”)
3. Date ( x = dt, format = “%m / %d / %Y”)
4. none of the above

ANS: C

• P is the boxplot for the data. How to find outlier from boxplot
1. P\$outlier
2. P\$whiskers
3. P\$box
4. P\$out

ANS: D

• From the above P box plot, find the odd one out about P\$stats:
1. It gives information about minimum value, 25 %, median, 75 %, maximum value
2. It gives information about Q1, IQR, Q3
3. It gives information about minimum value, 25 %, mean , 75 %, maximum value
4. Outliers can be defined by Q1 -1.5*IQR

ANS: C

• Choose correct options to create two plots in plotting region
1. Subplot(2,1)
2. par(mfrow = c(1,2))
3. par(mfrow = c(2,1))
4. Subplot(1,2)

ANS: B,C

• Find odd one out:
1. Bar plot
2. Scatter plot
3. Pie chart
4. Box plot

ANS: D. As box plot is uni-variate graph

• True or False:

It is mandatory to have numeric data type to find correlation between two variables.

1. True
2. False

ANS: A

• Which function can be used to convert lowercase to uppercase
1. upper()
2. upper()
3. toupper()
4. to_upper()

ANS: C

• df1 and df2 are two different data frames. How to club two different data frames based on columns
1. rbind(df1,df2)
2. cbind(df1,df2)
3. ncols(df1,df2)
4. colbind(df1,df2)

ANS: B

• df1 <- data.frame(x = 1:4, y = c(‘a’, ‘b’, ‘c’))
1. This code will create the data frame of 4 rows and 2 columns
2. Data frame is having 2 rows and four columns
3. Syntax error
4. None of the above

ANS : C

• What will be the output for below mentioned code:

list_data <- list (c ( “One”, “Two”, “Three” ), matrix ( c (3, 10, 15, 14, -2, 18), nrow = 2 ), list ( “green”, 12.3) )

1. Syntax error for not matching dimensions.
2. Create the list
3. Create the dataframe
4. None of the above

ANS: B

• Choose correct options

Find the length of two vectors:

Len_a = c (1, 2, 3, 4, NA, 5, 6 )

Len_b = c (1, 2, 3, 4, NULL, 5, 6)

1. Length of Len_a is 7
2. Length of Len_b is 7
3. Length of Len_b is 6
4. Length of Len_a is 6

ANS :  A, C

• a = c (1 , 2 , 3 , 4 , NA , 5 , 6 )

b= 100

success = as.factor( c (“S” , ”F” , “S” , “S” , ”F” , “S” , “F” , “F” ) )

list (a, b, success) -> success1

what will be the output of success1 [ [ 3 ] ]

1. Error: elements should have same dimensions
2. Levels : F S
3. S F S S F S F F
4. Error: Index out of bound

ANS: B

• Find odd one out :

Summary of the data frame provide values like

1. Mean
2. Median
3. 1st Quartile
4. Mode

ANS: D

• What is the output of nchar ( “Count Words” ):
1. 11
2. 10
3. 1
4. 2

ANS: A

• What is the output of length( “Count Words” ):
1. 1
2. 11
3. 2
4. Error

ANS: A

• What is the function to remove NA values from the data frames
1. omit()
2. drop()
3. remove()
4. pop()

ANS: A

• a = “New World”

How to extract “New” from the given string a

1. substr(a,1,3)
2. substring(a,1,3)
3. substr(a,0,2)
4. substring(a,0,2)

ANS : B

• Find odd one out related to graph:
1. v
2. x-label
3. ylab
4. main

ANS: B

• If A = matrix (1:16 , 4 , 4)

Then what is A[2,3]?

1. 9
2. 8
3. 7
4. 10

ANS : D

• If A = matrix (1:16 , 4 , 4) then how can we get below mentioned matrix?

1. A [ 3 : 4 , 1 : 4 ]
2. A [- c ( 1 : 2 ), -c (2 , 3 ) ]
3. A [ 3 : 4 , c ( 1 , 4 ) ]
4. Both b and c

ANS: D

• Choose correct option(s)
1. Setwd() is used set the path for saving R code.
2. Setwd() is used to set the path for accessing the file.
3. Both a and b
4. None of the above

ANS: B

• A=10

B=15

How to display 10 < 15?

1. print ( A “ < ” B )
2. paste ( A + “ < ” + B )
3. paste ( A , “ < ”, B )
4. print ( A + “<” + B)

ANS: C

• find_val = c(“NEW”, “New Delhi”, “NEW Year”, “Happy New”)

What is the correct option to find out string that begins with “New”

1. grep ( pattern = “^New” , x = find_val)
2. sub ( pattern = “^New” , x = find_val)
3. grep ( pattern = “New*” , x = find_val)
4. grep ( pattern = “New^” , x = find_val)

ANS: A

• find_val = c(“abc val”, “val New Delhi val”, “NEW val Year”, “val Happy New”)

What is the output of the following code?

sub(pattern = “val”,replacement = “*”,x = find_val,ignore.case = T)

1. “abc *” “* New Delhi *” “NEW * Year”      “* Happy New”
2. “* abc *” “* New Delhi val” “NEW * Year”      “* Happy New”
3. “abc *” “* New Delhi val” “NEW * Year”      “* Happy New”
4. Error

ANS : C

### Author: 