Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

How do you transpose columns and rows in R?

Answer»

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

Note: R provides a wide variety of STATISTICAL (linear and nonlinear modeling, classical statistical tests,) and also GRAPHICAL techniques, which is highly extensible. Read our LIST of r programming interview questions to get BETTER in this language and even start working on your own data science project!

2.

How do you make a random walk in R

Answer»

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
3.

How do you match a string in R?

Answer»

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

Note: R allows various integration with its PROCEDURES written in the C, C++, .Net, Python, or the FORTRAN languages for efficiency. Read answers to the r coding interview questions carefully to UNDERSTAND the SUBJECT and get that dream job.

4.

What are the different type of sorting algorithms available in R language?

Answer»

There are 5 types of different sorting ALGORITHMS PRESENT in R programming. They are:

  • Bucket Sort
  • Merge Sort
  • Bubble Sort
  • Quick Sort
  • Selection Sort
5.

What is the use of with () and by () function in R?

Answer»

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.

6.

What does GSUB do in R?

Answer»

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.

7.

What is plots in R?

Answer»

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

Note: R's core is actually an interpreted computer language allowing the branching and looping along with modular programming using functions. Read more of our r interview questions to understand the core of this language and its workings

8.

What does the subset function do in R?

Answer»

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.
9.

How does random forest work in R?

Answer»

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.

10.

What is cbind and rbind in R?

Answer»

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)

11.

What is the use of R markdown?

Answer»

R Markdown is a FILE format that is used for making dynamic documents within R.

Did you know?

R was initially written by ROBERT Gentleman and Ross Ihaka at the Department of Statistics at the University of Auckland, New ZEALAND. R made its first PUBLIC appearance in 1993. Read our list of r programming INTERVIEW questions to get acquainted with this language.

12.

What are the features of R programming?

Answer»

Here are the 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.