R Interview Questions And Answers

Define r language?

R is a programming language for data analysis and graphics as it provides facility for reading, manipulating and computing data, conducting statistical analysis and displaying the results. It is a command line driven program means the commands evaluate and execute in the console.
Who created R programming language and when?

R programming language created in the early 1990s by Ross Ihaka and Robert Gentleman of the Statistics Department of the University of Auckland and it is currently maintained by the R core-development team.
What are the some popular GUIs for R.

There are some free GUIs available for R. Among them the most popular are -
  • RStudio
  • StatET
  • Deducer
How can we remove object from r?

The functions remove() and rm() are used to remove objects from the working directory.
How to write comments in R?

R supports single line comment same style as in shell using # in the beginning of the statement.
# First program in R language
str <- "Hello World!"
print (str)
What are the different types of data types in R?

These are the most frequently used data types
  • Vectors
  • Lists
  • Matrices
  • Arrays
  • Factors
  • Data Frames
What are nrow and ncol in Matrix?

The number of rows and columns of the matrix is assigned in nrow and ncol.
What is factors?

Factors are a special variable type for storing categorical variables. A factor can contain both integers and strings and it is generally used in statistical modeling. The factor() function is used to create a factor.
What is the difference between vector and list?

A vector represents a set of elements of the same mode, which can be integer, floating number, character, complex and so on while a list may contain different objects. A vector have all elements of the same type, but a list may contain elements of different types.
What is Matrix?

A matrix (plural: matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. It has two dimensional structure. All columns in a matrix are the same type and of the same length. In R, a matrix is created by using matrix() function.
How to declare a data frame in r?

A data frame is created by data.frame() function.
df <- data.frame(id = c(1:4), name = c("Mary", "Soy", "Alexa", "Roxy"), class = 5)
  id  name class
1  1  Mary     5
2  2   Soy     5
3  3 Alexa     5
4  4  Roxy     5
What is Colon Operator?

The colon operator generates a regular sequence, which is equivalent to interaction(a,b) but the levels are ordered and labelled differently.
What is belongs to operator?

The %in% operator identifies whether an element belongs to a vector or not.
What is the operator of vector multiplication with its transpose?

The %*% operator performs multiplication of a vector with its transpose.
How do you create a vector of sequence 10 to 30?

The colon operator generates a regular sequence of numbers. It requires starting and end value of the sequence.
x <- 10:30
How do you create a vector of sequence from 10 to 30 and each next element increment by 0.3?

R provides seq() function to generate a vector of sequence of numbers. The below code generates a vector of sequence beginning from 1 to 5 and each next element increment by 0.3.
x <- seq(10, 30, by=0.3)
How do you access and change the dimnames values of matrix?

R provide colnames() and rownames() functions to access and change the dimnames values. The below code returns the columns and rows dimnames of matrix M.
[1] "a" "b" "c"
[1] "x" "y"
Which function is used to know the structure of a data frame?

R provides str() function to get the structure of the data frame.
How can we add new rows in the existing data frame?

R provides rbind() function to add new rows in the existing data frame. For this, we have to create a second data frame and merge to the existing one.
Define factors in R?

Factor is a special variable type for storing categorical variables as levels, it is generally used in statistical modeling. It may contain both numeric and character values, but the factor levels will always be character values.
What is repeat loop?

Repeat loop is the easiest loop in R. It is similar to the do-while loop of other languages. In this, the conditional check is written at the end of the loop iteration, so the statement is executed first before the condition is tested.
What is syntax of for loop in r?

Syntax of the for loop in R
for(value in vector){
What is the role of paste() function in string?

The paste() function concatenates several strings and returns the result in one long string.
How do you get length of a string in r?

The nchar() function finds the length of a string.
How do you get the list of all installed packages in your system?

The library() function displays all the installed packages in your system.
What is the role of libPaths()?

R provides libPaths() function to know the library paths in your system.
What is the syntax to uninstall a package?

The followin syntac uninstall a package.
remove.packages(pkg, lib)
Here, pkg is the name of the package to remove and lib is the library directory to remove.
Give a name of package for interacting with JSON?

R provides 'jsonlite' package for interacting with JSON. To install this package, use the install.package() command with the package name.
Give a name of package to connect with MySQL?

R provides a RMySQL package to connect to MySQL.
Which function is used to list all the tables under the database?

The dbListTables() function is used to list all tables under the database.
Write the syntax to create connection with mongodb?

mongo(collection = "test", db = "test", url = "mongodb://localhost", options = ssl_options())
What is the scatter plot?

The scatter plot is a type of plot, especially to show the relationship between two variables. One of the two variables is scaled horizontally and the other is scaled vertically, and the graph is plotted on a Cartesian plane based on these variable positions.
Define histogram with syntax?

A histogram is an accurate representation of the distribution of numerical data. R provides hist() function to generate a histogram. This function takes a vector as input. It is similar to the bar chart except a bar graph relates two variable, but a histogram relates only one variable.
What is r box plots?

Boxplot is a visual representation of data that shows the minimum, first quartile, median, third quartile and maximum in the graph. The median is a line that divides the box into two parts.
What are the different sorting algorithms present in R?

The different sorting algorithms present in R are -
  • Bucket Sort
  • Selection Sort
  • Quick Sort
  • Bubble Sort
  • Merge Sort
What is the use of abline() function?

The abline() function is a low level plotting function which adds one or more straight lines (vertical, horizontal or regression lines) to the current plot.
What is the role of t.test()?

The t.test( ) function is one of the most common tests in statistics and used to determine the means of two groups are equal to each other or not. There are different types of t.test(), like one sample t-test(), paired samples t-test(), independent samples t-test().
What is the Hovplot() function?

The Hovplot() function is defined in HH package to conduct graphics test for homogeneity.
What is the default memory limit in R?

The default memory limit in R is 3GB for 32-bit system memory and 8TB for 64-bit system memory.
How do you increase the default memory limit in R?

We can increase the default memory limit in R with the help of memory.limit(size) function, where the size is in MB.
How do you represent the missing values in R?

In R, the missing values are represented by NA (capital letters).
What is the difference between lapply() and sapply() functions?

The lapply() function takes list, vector, data frame as input and returns only list as output, ane the sapply() function takes list, vector or data frame as input and returns only vector as output.
What are R packages?

R provides a good collection of functions for solving many developmental problems. These collections are called packages. Some packages are installed by default with R installation. Most of the packages are available on R official website http://CRAN.R-project.org/, that we can easily install later as per our requirement.
What is GGobi?

GGobi is a powerful tool for data exploration, and the integration with R.
What is the use of rapply() function?

The rapply() function is the recursive apply, which apply a function to all elements of a list recursively.