---Advertisement---
Data Science R Language

R Language Interview Question-Answer

By Smart Answer

Updated on:

---Advertisement---

R Language Interview Question-Answer Part – 2

R Language Interview Question-Answer Part – 3

Q.1 Which of the following while loops will print numbers from 1 to 4?

       A. x<-1 while(x < 5) {x <- x+1; print(x);}

       B. x<-1 while(x < 5) do { print(x); x <- x+1;}

       C. x<-1 while(x < 5) do {x <- x+1; print(x);}

       D. x<-1 while(x < 5) { print(x); x <- x+1;}

Ans : x<-1 while(x < 5) { print(x); x <- x+1;}


Q.2 What would be the result of following code?

       A. x <- c(“x”, “y”, “z”) as.logical(x)

       B. “x” “y” “z”

       C. NA NA NA

       D. NaN NaN NaN

       E. x y z

Ans : NA NA NA


Q.3 What command will you enter in the R console to get help on how to quit R?

       A. help q

       B. man quit

       C. help(q)

       D. info(quit)

Ans : help(q)


Q.4 Which of the following statements is correct?

       A. Control structures like if, while, and for are used to control the flow of an R program

       B. The only way to exit a repeat loop is to call break

       C. Infinite loops should generally be avoided

       D. All the options

Ans : All the options


Q.5 What is the output of the R code?
m <- c(1, 2, 3) n <- c(6, 5, 4) (m < 2) & (n > 5)

       A. An error is thrown because the wrong operator is used

       B. {1 2 4}

       C. True

       D. TRUE FALSE FALSE

Ans : True


Q.6 In R, the subsequent data types are all atomic data types except _____________.

       A. Logical

       B. Data frame

       C. Float

       D. Character

Ans : Data frame


Q.7 What would be the result of following code?
x <- 0:4 as.logical(x)

       A. FALSE TRUE TRUE TRUE TRUE

       B. “0” “1” “2” “3” “4”

       C. NA NA NA NA NA

       D. 0 1 2 3 4

Ans : FALSE TRUE TRUE TRUE TRUE


Q.8 What is the class of the object defined by the expression x<- c(4,”a”,TRUE) in R?

       A. Integer

       B. Logical

       C. Character

       D. Numeric

       E. Float

Ans : Character


Q.9 Which of the following statements is correct?

       A. Use explicit TRUE and FALSE values when indicating logical values

       B. R operates on named data structures

       C. rm command is used to remove objects in R

       D. All the options

Ans : All the options


Q.10 Which of the following statements is correct?

       A. NaN can also be thought of as a missing value

       B. Number Inf represents infinity in R

       C. The value Nan represents undefined value

       D. All the options

Ans : The value Nan represents undefined value


Q.11 What would be the output of the subsequent code?
x <- c(“a”, “b”, “c”, “c”, “d”, “a”) x[c(1, 3, 4)]

       A. “a” “b” “c”

       B. “b” “c” “d”

       C. “a” “c” “c”

       D. “a” “c” “d”

Ans : “a” “c” “c”


Q.12 Assume that you have a vector x <- c(3,5,1,10,12,6) and you wish to set all elements of this vector that are smaller than 6 to be equal to 0, what R code accomplishes this?

       A. x[x==0]

       B. x[x==6]<-0

       C. x[x<6]==0

       D. x[x<6]<-0

Ans : x[x<6]<-0


Q.13 If I have two vectors, x<-c(1,3,5) and y<-c(3,2,10), what does rbind(x,y) give?

       A. A vector length of 3

       B. A 3 x 3 matrix

       C. A 3 x 2 matrix

       D. A 2 x 3 matrix

       E. A vector length of 2

Ans : A 2 x 3 matrix


Q.14 Which function is used to generate Sequences in R?

       A. sequence()

       B. order()

       C. seqn()

       D. seq()

Ans : seq()


Q.15 An important property of vectors in R is that ___________.

       A. A vector cannot have attributes like dimensions

       B. Elements can only be character or numeric

       C. All elements must be of the same class

       D. Elements can be of different classes

Ans : All elements must be of the same class


Q.16 Which command allows you to get the median tree Height of the R sample dataset “trees”?

       A. median(trees$Height)

       B. median(trees.Height)

       C. median(trees)

       D. avg.median(trees$Height)

Ans : median(trees$Height)


Q.17 Which R command creates a 2 by 2 matrix with the values 1, 2, 3, and 4?

       A. m <- [1,2,;3,4]

       B. m <- matrix ( 1 -> 4; 2, 2)

       C. m <- matrix(1:4, 2, 2)

       D. m <- cbin( c(1,2),c(2,1) )

Ans : m <- matrix(1:4, 2, 2)


Q.18 What would be the result of following code?
x <- 4 class(x)

       A. integer

       B. numeric

       C. double

       D. real

Ans : numeric


Q.19 Which function can be used to create collection of vectors objects?

       A. cp()

       B. c()

       C. concat()

       D. None of the options

Ans : c()


Q.20 What is the function in R to get the # of observations in a data frame?

       A. nrow()

       B. nobs()

       C. n()

       D. ntotal()

Ans : nrow()


Q.21 Which of the following statement would print “0” “1” “2” “3” “4” “5” “6” for the following R code?
> x <- 0:6

       A. as.character(x)

       B. as.logical(x)

       C. as.numeric(x)

       D. as.num(y)

Ans : as.character(x)


Q.22 Point out the correct statement?

       A. rep() is be used for replicating an object in various complicated ways

       B. seq() function has four arguments

       C. sequence() is a more general facility for generating sequences

       D. numerical vectors are generated by conditions

Ans : rep() is be used for replicating an object in various complicated ways


Q.23 What will be the output of the following R code?
x <- c(“a”, “b”, “c”) > as.numeric(x)

       A. Warning

       B. Error

       C. Abnormal termination

       D. Prints x

Ans : Warning


Q.24 What will be the output of the following R code?
> x <- c(“a”, “b”, “c”) > as.logical(x)

       A. a b c

       B. NA NA NA

       C. 0 1 2

       D. 6 8 9

Ans : NA NA NA


Q.25 Point out the correct statement?

       A. The elements of a logical vector cannot have the values TRUE, FALSE, and NA

       B. Matrices are vectors with a dimension attribute

       C. Numerical vectors are generated by conditions

       D. seq() function has four arguments

Ans : Matrices are vectors with a dimension attribute


Q.26 Which of the following is invalid assignment?

       A. > m <- matrix(nrow = 2, ncol = 3)

       B. > m <- matrix(nrow = 2, ncol = 3.5)

       C. > m <- mat(nrow = 2, ncol = 5)

       D. > m <- mat(nrow = 2, ncol = 3)

Ans : > m <- matrix(nrow = 2, ncol = 3)


Q.27 What will be the output of the following R code?
> m <- matrix(nrow = 2, ncol = 3)
> dim(m)

       A. 3 2

       B. 2 3

       C. 2 2

       D. 4 5

Ans : 2 3


Q.28 What will be the output of the following R code?
> m <- 1:10
> m

       A. 1 2 3 4 5 6 7 8 9 10

       B. 1 2 3 4 5 6 7 8 9 10 11

       C. 0 1 2 3 4 5 6 7 8 9 10

       D. 10 9 8 6 5 4 2 3 1 2

Ans : 1 2 3 4 5 6 7 8 9 10


R Language Interview Question-Answer Part – 2

R Language Interview Question-Answer Part – 3

Smart Answer

---Advertisement---

Related Post

Birst Interview Question-Answer

Q.1 _____________ is a Java-based application that enables Birst to connect to any data source.        A. Birst Space        B. Birst Connect   ...

Image Classification Interview Question-Answer

Q.1 Identify the unstructured data from the following.        A. Excel data        B. Image        C. Data from mySQL DB   ...

Salesforce Einstein Analytics Interview Question-Answer

Q.1 Which of the following is the essential element of Salesforce Einstein?        A. Computing Capacity        B. Data        C. Time ...

R Language Interview Question-Answer Part – 3

R Language Interview Question- – 1 R Language Interview Question- – 2 Q.1 The four most frequently used types of data objects in R are vectors, matrices, data ...

Leave a Comment