Fatskills
Practice. Master. Repeat.
Study Guide: All The Useful R Programming Interview Questions & Answers
Source: https://www.fatskills.com/r-language-programming/chapter/all-the-useful-r-programming-interview-questions-answers

All The Useful R Programming Interview Questions & Answers

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~5 min read

R was initially written by Robert Gentleman and Ross Ihaka at the Department of Statistics at the University of Auckland, New Zealand. R was introduced way back in 1993. 

Q 1. What are the features of R programming?

Here are some important features of R Programming:

It is free, open-source, and can be adjusted according to a user's project requirements.
It has a highly active and growing community, which helps beginners gain support to learn this language.
R is basically an Object Oriented Programming language which consists of a versatile package called Rshiny which can be used to make full-fledged Web apps.
R has packages like ddR and multiDplyr, enabling it to use distributed computing for handling large data sets.
R is an interpreted language, meaning it does not require a compiler to execute its code.

Q 2. What is the use of R markdown?
R Markdown is a file format that is used for making dynamic documents within R.

Q 3. What is cbind and rbind in R?
Cbind in R is a function that stands for column-bind. It is used for combining vectors, matrices, and data frames by columns.

Syntax:
cbind(data_input, new_column)

On the other hand, Rbind is a function in R that stands for row binds. It is used to bind the data frames by doing a simple joining or concatenation of two or more tables row-wise.

Syntax:
rbind(y1,y2)

Q 4. How does random forest work in R?
Random forests in R programming work in the same fashion as decision trees. It combines all the output from the multiple decision trees and comes up with its output. However, one significant difference from decision trees is that it does not select all the variables and data points in each tree. It just randomly selects and samples variables from each tree and then combines the output.

Q 5. What does the subset function do in R?
The subset function in R is used for multiple purposes such as:

Returning subsets of a vector, matrix, or data frame which meeting a particular condition
Selecting specific elements of a data structure.

Q 6. What are plots in R?
Plots in R are a useful tool whose main purpose is to help in graphically presenting data. It can be used to display, compare, composition, distribution, and relationships between variables and data points.

Plots can be of 6 types:
Histogram
Heatmaps
Correlogram
Scatterplot
Box plot
Bar/Line Chart

R's core is actually an interpreted computer language allowing the branching and looping along with modular programming using functions. 

Q 7. What does GSUB do in R?
The GSUB is a function in R is used to replace all matches of a string. If the parameter is a string vector, it returns a string vector with the same length and attributes.

Q 8. What is the use of with () and by () function in R?
The with() function in R is used to perform expressions using the variables inside a list or data frame. The with function will also keep track of any changes made, which includes adding or deleting elements and returning a new object with revised contents.

The by() function in R is used to apply a function to some specified subsets within a data frame.

Syntax:
by(data, data$byvar, FUN) data$byvar: It is a factor or a list of factors on which the function is applied
FUN: Is a function that is applied to the subsets of data.

Q 9. What are the different type of sorting algorithms available in R language?
There are 5 types of different sorting algorithms present in R programmin
g. They are:

Bucket Sort
Merge Sort
Bubble Sort

Quick Sort
Selection Sort

Q 10. How do you match a string in R?
To match a string with some parameters, the grep() function is used. The grep() function returns the index at which the pattern is found in the string. It also tells us the location of the specified string in the vector.

Example:
Find all the instances of 'he' in the string.

str <- c("Hello", "hello", 'human', "hi", "hey")
grep('he', str)

Output
[1] 1 2 5

R allows various integration with its procedures written in the C, C++, .Net, Python, or the FORTRAN languages for efficiency.

Q 11. How do you make a random walk in R?
Here are the correct steps for generating a random walk using the R language:

Use the arima.sim() to generate a Randomwalk model.
Now, go to the model argument and set it equal to a list(order = c(0, 1, 0)) for generating a RW-type model.
After that, set 'n' equals 10 sp as to produce 10 different observations and then save this to the random_walk.
Now, use the ts.plot()function for plotting your random_walk data.
Next, use the diff() function for calculating the first difference between sets of your random_walk data.
Now, you can save this as random_walk_diff.
Finally, you should use another call to ts.plot() to be used for plotting random_walk_diff

Q 12. How do you transpose columns and rows in R?
There are two ways for transposing rows and columns in R.

Using t to just transpose the data frame as if it would be a matrix
Use tidyr::spread along with tidyr::gather

R provides a wide variety of statistical (linear and nonlinear modeling, classical statistical tests,) and also graphical techniques, which is highly extensible. 
 


⚡ Recently practiced quizzes in this class

ADVERTISEMENT