R Language quiz questions

R Language interview questions

  • 1.

    __________ prints out the function call stack after an error occurs.

    1. trace()

    2. traceback()

    3. back()

    4. All of the mentioned

    Answer
  • 2.

    What would be the output of the following code ?

    > printmessage <- function(x) {
    +                      if(x > 0)
    +                           print("x is greater than zero")
    +                      else
    +                           print("x is less than or equal to zero")
    +                      invisible(x)
    + }
    > printmessage(NA)

     

    1. Error

    2. Warning

    3. Messages

    4. All of the mentioned

    Answer
  • 3.

    What would be the output of the following code ?

    > printmessage2 <- function(x) {
    +                      if(is.na(x))
    +                              print("x is a missing value!")
    +                      else if(x > 0)
    +                              print("x is greater than zero")
    +                      else
    +                              print("x is less than or equal to zero")
    +                      invisible(x)
    + }
    > printmessage2(NA)

     

    1. “x is a missing value!”

    2. “x is greater than zero”

    3. “x is less than or equal to zero”

    4. None of the mentioned

    Answer
  • 4.

    Which of the following code represents internal representation of a Date object ?

    1. class(as.Date(“1970-01-02”))

    2. unclass(as.Date(“1970-01-02”))

    3. unclassint(as.Date(“1970-01-02”))

    4. All of the mentioned

    Answer
  • 5.

    What will be the value of following expression ?

    1. Warning in log(c(-1, 2)): NaNs produced

    2. Error in log(c(-1, 2)): NaNs produced

    3. Message

    4. All of the mentioned

    Answer
  • 6.

    What will be the output of the following code ?

    > printmessage <- function(x) {
    +              if(x > 0)
    +                    print("x is greater than zero")
    +              else
    +                    print("x is less than or equal to zero")
    +              invisible(x)
    + }
    > printmessage(1)

     

    1. Error

    2. Warning

    3. Messages

    4. All of the mentioned

    Answer
  • 7.

    Point out the correct statement :

    1. Vectorizing the function can be accomplished easily with the Vectorize() function

    2. There are different levels of indication that can be used, ranging from mere notification to fatal error

    3. Vectorizing the function can be accomplished easily with the vector() function

    4. None of the mentioned

    Answer
  • 8.

    Warnings are generated by the _________ function

    1. warning()

    2. error()

    3. run()

    4. None of the mentioned

    Answer
  • 9.

    What would be the value of following expression ?

      > log(-2.3)

     

    1. Warning in log(-2.3): NaNs produced

    2. 1

    3. NULL

    4. 0

    Answer
  • 10.

    Point out the correct statement :

    1. R has a number of ways to indicate to you that something’s not right

    2. Executing any function in R may result in the condition

    3. “condition” is a generic concept for indicating that something unexpected has occurred

    4. All of the mentioned

    Answer
  • 11.

    _________ is an indication that a fatal problem has occurred and execution of the function stops

    1. message

    2. error

    3. warning

    4. All of the mentioned

    Answer
  • 12.

    What will be the output of following code ?

    > x <- list(a = 1:4, b = rnorm(10), c = rnorm(20, 1), d = rnorm(100, 5))
    > sapply(x, mean)

     

    1. a b c d
      2.500000 -0.251483 1.481246 4.968715
    2. a b c d
      2.500000 -3.251483 2.481246 5.968715
    3. a b c d
      3.500000 0.251483 1.481246 4.968715
    4. Error

    Answer
  • 13.

    What will be the output of the following code ?

    > f <- function(elt) {
    + elt[, 1]
    + }
    > lapply(x, f)

     

    1. $a
      [1] 1 2
      $b
      [1] 1 2 3
    2. $a
      [1] 1 2 3
      $b
      [1] 1 2 3
    3. $a
      [1] 1 2 3
      $b
      [1] 1 2
    4. All of the mentioned

    Answer
  • 14.

    Which of the following is valid body of split function ?

    1. function (x, f)

    2. function (x, drop = FALSE, …)

    3. function (x, f, drop = FALSE, …)

    4. All of the mentioned

    Answer
  • 15.

    The _____ function takes a vector or other objects and splits it into groups determined by a factor or list of factors.

    1. apply()

    2. lsplit()

    3. split()

    4. mapply()

    Answer
  • 16.

    What will be the output of the following code ?

    > x <- list(a = matrix(1:4, 2, 2), b = matrix(1:6, 3, 2))
    > lapply(x, function(elt) { elt[,1] })

     

    1. $a
      [1] 1 2
      $b
      [1] 1 2 3
    2. $a
      [1] 1 2 3
      $b
      [1] 1 2 3
    3. $a
      [1] 1 2 3
      $b
      [1] 1 2
    4. All of the mentioned

    Answer
  • 17.

    Point out the correct statement :

    1. split() takes elements of the list and passes them as the first argument of the function you are applying

    2. You can use tsplit() to evaluate a function single time each with a same argument

    3. Sequence of operations is sometimes referred to as “map-reduce”

    4. None of the mentioned

    Answer
  • 18.

    Which of the following code will print the following result ?

    [[1]]
    [1] 2.263808
    [[2]]
    [1] 1.314165 9.815635
    [[3]]
    [1] 3.270137 5.069395 6.814425
    [[4]]
    [1] 0.9916910 1.1890256 0.5043966 9.2925392

     

    1. > x <- 1:4
      > lapply(x, runif, min = 0, max = 10)

       

    2. > x <- 1:4
      > lapply(x, runif, min = 0, max = 9)

       

    3. > x <- 1:3
      > lapply(x, runif, min = 0, max = 10)

       

    4. None of the mentioned

    Answer
  • 19.

    What will be the output of the following code ?

    > x <- 1:4
    > lapply(x, runif)

    A)

    [[1]]
    [1] 0.02778712
    [[2]]
    [1] 0.5273108 0.8803191
    [[3]]
    [1] 0.37306337 0.04795913 0.13862825
    [[4]]
    [1] 0.3214921 0.1548316 0.1322282 0.2213059

    B)

    [[1]]
    [1] 1.02778712
    [[2]]
    [1] 2.5273108 0.8803191
    [[3]]
    [1] 3.37306337 0.04795913 0.13862825
    [[4]]
    [1] 0.3214921 0.1548316 0.1322282 0.2213059

    C)

    [[1]]
    [1] 1.02778712
    [[2]]
    [1] 0.5273108 0.8803191
    [[3]]
    [1] 0.37306337 0.04795913 0.13862825
    [[4]]
    [1] 3.3214921 2.1548316 1.1322282 0.2213059

    D) None of the mentioned

    1. A

    2. B

    3. C

    4. D

    Answer
  • 20.

    Point out the wrong statement :

    1. The sapply() function behaves similarly to lapply()

    2. With multiple factors and many levels, creating an interaction can result in many levels that are empty

    3. apply() can be thought of as a combination of split() and sapply() for vectors only

    4. All of the mentioned

    Answer

© 2017 QuizBucket.org