R Language interview questions

R Language quiz questions

  • 1.

    What do you understand by a workspace in R programming language?

    Answer:

    The current R working environment of a user that has user defined objects like lists, vectors, etc. is referred to as Workspace in R language.

    View
  • 2.

    What are the rules to define a variable name in R programming language?

    Answer:

    A variable name in R programming language can contain numeric and alphabets along with special characters like dot (.) and underline (-). Variable names in R language can begin with an alphabet or the dot symbol. However, if the variable name begins with a dot symbol it should not be a followed by a numeric digit.

    View
  • 3.

    What is the difference between library() and require() functions in R language?

    Answer:

    There is no real difference between the two if the packages are not being loaded inside the function. require () function is usually used inside function and throws a warning whenever a particular package is not found. On the flip side, library () function gives an error message if the desired package cannot be loaded.

    View
  • 4.

    How will you check if an element 25 is present in a vector?

    Answer:

    There are various ways to do this-

    1. It can be done using the match () function- match () function returns the first appearance of a particular element.
    2. The other is to use %in% which returns a Boolean value either true or false.
    3. Is.element () function also returns a Boolean value either true or false based on whether it is present in a vector or not.
    View
  • 5.

    How will you create scatterplot matrices in R language?

    Answer:

    A matrix of scatterplots can be produced using pairs. Pairs function takes various parameters like formula, data, subset, labels, etc.

    The two key parameters required to build a scatterplot matrix are –

    • formula- A formula basically like ~a+b+c . Each term gives a separate variable in the pairs plots where the terms should be numerical vectors. It basically represents the series of variables used in pairs.
    • data- It basically represents the dataset from which the variables have to be taken for building a scatterplot.
    View
  • 6.

    What is the purpose of using Next statement in R language?

    Answer:

    If a developer wants to skip the current iteration of a loop in the code without terminating it then they can use the next statement. Whenever the R parser comes across the next statement in the code, it skips evaluation of the loop further and jumps to the next iteration of the loop.

    View
  • 7.

    How can you resample statistical tests in R language?

    Answer:

    Coin package in R provides various options for re-randomization and permutations based on statistical tests. When test assumptions cannot be met then this package serves as the best alternative to classical methods as it does not assume random sampling from well-defined populations.

    View
  • 8.

    There is a function fn(a, b, c, d, e) a + b * c - d / e. Write the code to call fn on the vector c(1,2,3,4,5) such that the output is same as fn(1,2,3,4,5).

    Answer:

    do.call (fn, as.list(c (1, 2, 3, 4, 5)))

    View
  • 9.

    What is the use of sample and subset functions in R programming language?

    Answer:

    Sample () function can be used to select a random sample of size ‘n’ from a huge dataset.

    Subset () function is used to select variables and observations from a given dataset.

    View
  • 10.

    How will you measure the probability of a binary response variable in R language?

    Answer:

    Logistic regression can be used for this and the function glm () in R language provides this functionality.

    View
  • 11.

    How can you verify if a given object “X” is a matrix data object?

    Answer:

    If the function call is.matrix(X) returns true then X can be considered as a matrix data object otheriwse not.

    View
  • 12.

    What do you understand by element recycling in R?

    Answer:

    If two vectors with different lengths perform an operation –the elements of the shorter vector will be re-used to complete the operation. This is referred to as element recycling.

    Example – Vector A <-c(1,2,0,4) and Vector B<-(3,6) then the result of A*B will be ( 3,12,0,24). Here 3 and 6 of vector B are repeated when computing the result.

    View
  • 13.

    How can you verify if a given object “X” is a matric data object?

    Answer:

    If the function call is.matrix(X ) returns TRUE then X can be termed as a matrix data object.

    View
  • 14.

    How do you write R commands?

    Answer:

    The line of code in R language should begin with a hash symbol (#).

    View
  • 15.

    How will you read a .csv file in R language?

    Answer:

    read.csv () function is used to read a .csv file in R language. Below is a simple example –

    filcontent <-read.csv (sample.csv)

    print (filecontent)

    View
  • 16.

    Differentiate between seq (6) and seq_along (6)

    Answer:

    Seq_along(6) will produce a vector with length 6 whereas seq(6) will produce a sequential vector from 1 to 6  c( (1,2,3,4,5,6)).

    View
  • 17.

    Differentiate between lapply and sapply.

    Answer:

    If the programmers want the output to be a data frame or a vector, then sapply function is used whereas if a programmer wants the output to be a list then lapply is used. There one more function known as vapply which is preferred over sapply as vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is difficult to be implemented and more verbose.

    View
  • 18.

    What happens if the application object is not able to handle an event?

    Answer:

    The event is dispatched to the delegate for processing.

    View
  • 19.

    Write a function in R language to replace the missing value in a vector with the mean of that vector.

    Answer:

    mean impute <- function(x) {x [is.na(x)] <- mean(x, na.rm = TRUE); x}

    View
  • 20.

    How can you debug and test R programming code?

    Answer:

     R code can be tested using Hadley’s testthat package.

    View

© 2017 QuizBucket.org