R Interview Questions & Answers

Question & Answers

R Interview Questions AnswersR programming language is popular day by day because there is a huge requirement of R programmers in the market and in this post "R Interview Questions Answers" I have tries to cover the concepts and usually asked interview questions to R programmers by the interviewers. R is one of the most popular programming languages for Big Data professionals who are engaged in dealing with huge volume of data. R Interview Questions Answers have been designed such a way that you get basic and advance knowledge of R programming language. R Programming language is used for statistical computing and graphics. R is also an interpreted language, using command line interpreter users can access it.

List of  R Interview Questions Answers with examples

1. What is R language?

Like other high level languages like C#, Java, R is also a high level programming language. For displaying the large volume of data  in  graphical format it works as a very powerful tool. It is used for  statistical analysis, data visualization, data manipulation, predictive modelling, forecast analysis etc., using many packages available in it......

2. What are the different data types in R?

Following are the data types in R.

1. Vectors(numerical, character, logical)

c() function is used to create vector which  combine the elements into a vector.

# Createing a vector.
MyVector<- c("Black","Red","White")
OUTPUT: [1]  "Black" "Red" "White"
2. Lists

A List is a R-object containing  ordered collection of objects. A list allows you to contain another list, function and other variety of elements.

# Createing a list.
MyList<- list(c(2,5,3),21.3,sin)
3. Matrices

A matrix is a two-dimensional rectangular data set. It can be created using a vector input to the matrix function.

# generates 5 x 4 numeric matrix
y<-matrix(1:20, nrow=5,ncol=4)
# another example
cells <- c(1,26,24,68)
rnames <- c("R1", "R2")
cnames <- c("C1", "C2")
mymatrix <- matrix(cells, nrow=2, ncol=2, byrow=TRUE,
dimnames=list(rnames, cnames)) 
4. Arrays

Arrays are similar to matrices but can have more than two dimensions.

# Creating an array.
arr <- array(c("Black","Red","White"),dimen2 = c(6,3,2))
5. Data Frames

A data frame is more general than a matrix, in that different columns can have different modes (numeric, character, factor, etc.).

d <- c(1,2,3,4)
e <- c("red", "white", "red", NA)
mydata <- data.frame(d,e,f)
names(mydata) <- c("ID","Color","Passed")
6. Factors

Another R objects are Factors objects. To Create Factors objects vector can be used.  To create Factors  you can use factor() function and to have the count of levels you can use nlevels functions.

3. Define the function for importing data from a CSV file.

Use the “read.csv()” function and specify the path of the file.


R creates a data frame on reading the csv files using this function.

4. Name the package which is used to install a package in R.

Use : install.packages("package Name")

5. Name the function which is used to create a boxplot graph.


6. How to convert the data in a JSON file to a data frame?

Using : as.data.frame()

7. How R commands are written?

By using # at the starting of the line of code like #division commands are written.

9. Define With() and By() function in R.

with() function applies an expression to a dataset.


By() function applies a function to each level of a factors.


10. Define library() and require() functions.

Library() function searches the desired package at specified path if package not found at  specified  path then gives an error message display. While Require() function is used inside function and throws a warning messages whenever a particular package is not found.

Library() function does not check if desired package is already loaded so it always loads the package. Require() function just checks if desired package is already loaded, if package not loaded then it loads the package.

if(!require(package, character.only=T, quietly=T)) {
install.packages (package)
library(package, character.only=T)

11. Write command for setting path for current working directory.


12. How missing values are represented in R?

?NA (capital letters)

13. Define col.max(x).

Column with  maximum value for each row is result of this function.

14. Define subset() function.

Subset()  selects the variables and observations.

15. Explain  sample() function.

Sample() function  generates a random sample of the size n from a dataset.

16. Define matrix and dataframes.

For various  data type you can use dataframe and for  similar type of data you can use matrix.

17. Define  "next" statement in R.

The "next" statement skips the current item in loops.

18. Define rm(x) function.

To remove vector from  R workspace use rm(x) function.

19. Define of hist() command.

To create histogram use hist() function

20. Suppose you want to apply same function on each element of array i.e calculating mean for each row in rows then which function you will use in R?


21. Explain is.matrix(mat).

is.matrix(mat) checks if "mat" is a matrix data object in R? Returns true or false.

22. List sorting algorithms.

  • Bucket Sort
  • Merge Sort
  • Selection Sort
  • Bubble Sort
  • Quick Sort

23. Define workspace in R.

Workspace is current domain or environment where R keeps the user defined objects like vector, lists etc.

24. Explain  Merge() function.

Merge() function merges the two data frames horizontally.

 Example : MergedData<-merge(data frame1,data frame2,by=’ID’)

25. Explain rbind() function.

rbind() function merges the  two data frames vertically.

Example: MegredData<- rbind(data frame1,data frame 2)

26. What does NaN indicate in R?

Impossible values are presented by NaN(Not a Number).

27. Name the function used for sorting in R?

For sorting  use order() function.

28. Define axes() function in R?

To create custom axes you can use axes() function.

29. Name function used to define the direction of outpt?

sink() function.

30. To check the packages currently loaded, which function is used?


31. To create log-linear models, which function is used?


32. Explain types of loops in R.

While Loop
name<-"While Loop Example"
For Loop
MyVector<- c("Black","Red","White")
for(vec in MyVector)
print (vac)

33. Define transpose.

To convert rows as columns of a matrix is called transpose.

34. Define rbind() function.

To join two data frames (datasets) vertically, rbind function is used. but the column of two datasets must be same.

Exampale : MergedData<- rbind(data frameA, data frameB)

35. Explain cor() and cov() function.

cor() is for producing Cor-relations while cov() function is for covariances .

36. How to create new variable in R programming?

For creating new variable assignment operator ‘<-’ is used.

34. What is the function of Save and Load command?

Save command is for storing R objects into a file.

Syntax: >save(abc,file=”abc.Rdata”)

load command is for storing R objects from a file.

Syntax: >load(”abc.Rdata”)

35. Define t-tests() function in R.

To test if means of two groups are equal or not, use t.test() function.

36. Define lapply and sapply in R.

  • lapply function generates a list as output accepting the list, vector or Data frame  as input.
  • sapply function generates a vector as output accepting the list, vector or Data frame  as input.

37. Define seq_along (8) and seq (8).

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

38. Define read.csv() function.

read.csv() function reads a csv file.

# Read CSV into R
MyData <- read.csv(file="c:/MyCSVFile.csv", header=TRUE, sep=",")

The above reads the file MyCSVFile.csv into a data frame that it creates called MyData.

39. How to define variable name in R?

  • A variable name in R  can contain numeric and alphabets along with special characters like dot (.) and underline (-).
  • Variable names in R can begin with an alphabet or the dot symbol.

40. What is the output of following?

data(package = .packages(all.available = TRUE))

Above code will  list all the data sets available in all R packages.

41. Define power analysis.

For experimental design Power analysis is  very helpful. Power analysis can be used for determining the effect of a given sample size. Pwr package in R is used for power analysis.

42. For re-randomization and permutations based on statistical tests which package is used in R?

If here is a requirement for re-randomization and permutations based on statistical tests then Coin package supports various options for this purpose.

43. Define "rcmdr" command.

To start the R commander GUI, type "rcmdr" command on console. R Commander is useful for importing data in R language.

44. List the packages used for exporting of data.

  • Excel(xlsReadWrite package required)
  • SPSS,SAS(foreign packages required)

45. Explain of abline() function.

To add straight lines to a plot using R software.

abline(h=yvalues, v=xvalues)

46. What are the steps for converting  a factor variable into numeric in R?

  • Use as.numeric() function
  • First Convert variables into Character
  • Convert output to Numeric
XN <- factor(c(41, 25, 6, 6, 6))
X1 = as.numeric(as.character(XN))

48. Name the super class of all view controller objects.

UIViewController class.

49. What is  doBY package?

doBy package supports the various functions like spiting data into groups and do some activity on these group.

50. Explain table( ), prop.table( ) and margin.table( ).

  • table( ) function is used to create frequency tables.
  • prop.table( ) function express Table Entries As Fraction Of Marginal Table.
  • margin.table( ) function compute Table Margin.

51. What is use of Pair() or splom() functions?

Both are used to create scatterplot matrices.

52. What is the use of leaps()?

leaps() does in-depth search for the best subsets of the variables  in linear regression.

53. What is cv.lm() function?

it does k-fold cross-validation and then provides the mean squared errors and then provides a graph of the predicted versus actual values and shows which group each point was in. It is defined under the DAAG package.

54. Which package is appropriate for  multivariate statistics including model selection methods?

robustbase package.

55. What is MANOVA?

The MANOVA stands for multivariate analysis of variance. It is used test/analyze data participating in multiple dependent variable at a time.

56. Define Poison regression.

In statistics, Poisson regression is a generalized linear model form of regression analysis used to model count data and contingency tables. Poisson regression assumes the response variable Y has a Poisson distribution, and assumes the logarithm of its expected value can be modeled by a linear combination of unknown parameters. A Poisson regression model is sometimes known as a log-linear model, especially when used to model contingency tables.(WIKIPEDIA)



This post "R Interview Questions Answers"  has been designed by experts of R language. All R Interview Questions Answers have with examples have been tested to give you accurate answers.  R is one of the most popular programming languages for Big Data professionals who are engaged in dealing with huge volume of data.  R Programming language is used for statistical computing and graphics. R is also an interpreted language, using command line interpreter users can access it.