R Programming Interview Questions and Answers Set 3

21. How to compile and run code in R?

  • Compiled Code – R is a high-level, expressive language. While C and C++ often require more lines of code to solve the same problem, they can be orders of magnitude faster than R.
  • Run the code – We find it easiest to use Rstudio. We can also paste the code in a normal R console or let R run a source file. However, these approaches are a bit less fail-safe.

22. How many types of functions are there in R string manipulation?

There are 8 functions in R string manipulation respectively

  • grep()
  • nchar()
  • paste()
  • sprintf()
  • substr()
  • strsplit()
  • regex()
  • gregexpr()

23. What is the use of subset() function and sample() function in R ?

In R, subset() functions help you to select variables and observations while through sample() function you can choose a random sample of size n from a dataset.

24. Explain how R commands are written?

In R, anywhere in the program, you have to preface the line of code with a #sign, for example

  • subtraction
  • division
  • note order of operations exists

25. What is the different type of sorting algorithms available in R language?

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

26. What is SAS and SPSS in R?

SAS stands for Statistical Analysis System. It was primarily developed to be able to analyze large quantities of agriculture data while SPSS stands for Statistical Package for the Social Sciences and was developed for the social sciences and was the first statistical programming language for the PC.

27. What is the main difference between an Array and a matrix?

A matrix is always two dimensional as it has only rows and columns. But an array can be of any number of dimensions and each dimension is a matrix. For example, a 3x3x2 array represents 2 matrices each of dimension 3×3.

28. What are Generic Functions in R?

R has three object-oriented (OO) systems: [[S3]], [[S4]] and [[R5]]. … A method is a function associated with a particular type of object. S3 implements a style of object-oriented programming called generic-function OO.

29. What are Features of Recursion?

The use of recursion, often, makes code shorter and looks clean.

  • It is a Simple solution for a few cases.
  • It expresses in a function that calls itself.

30. How to read data from the keyboard?

To read the data from keyboard we use three different functions:

  • scan()
  • readline()
  • print()