**Question 1. Explain About Data Import In R Language?**

**Answer :**

**R Commander is used to import data in R language. To start the R commander GUI, the user must type in the command Rcmdr into the console. There are 3 different ways in which data can be imported in R language-**

- Users can select the data set in the dialog box or enter the name of the data set (if they know).
- Data can also be entered directly using the editor of R Commander via Data->New Data Set. However, this works well when the data set is not too large.
- Data can also be imported from a URL or from a plain text file (ASCII), from any other statistical package or from the clipboard.

**Question 2. How Missing Values And Impossible Values Are Represented In R Language?**

**Answer :**

NaN (Not a Number) is used to represent impossible values whereas NA (Not Available) is used to represent missing values. The best way to answer this question would be to mention that deleting missing values is not a good idea because the probable cause for missing value could be some problem with data collection or programming or the query. It is good to find the root cause of the missing values and then take necessary steps handle them.

Data Mining Interview Questions

**Question 3. R Language Has Several Packages For Solving A Particular Problem. How Do You Make A Decision On Which One Is The Best To Use?**

**Answer :**

CRAN package ecosystem has more than 6000 packages. The best way for beginners to answer this question is to mention that they would look for a package that follows good software development principles. The next thing would be to look for user reviews and find out if other data scientists or analysts have been able to solve a similar problem.

**Question 4. Which Function In R Language Is Used To Find Out Whether The Means Of 2 Groups Are Equal To Each Other Or Not?**

**Answer :**

t.tests ()

Data Mining Tutorial

**Question 5. What Is The Best Way To Communicate The Results Of Data Analysis Using R Language?**

**Answer :**

The best possible way to do this is combine the data, code and analysis results in a single document using knitr for reproducible research. This helps others to verify the findings, add to them and engage in discussions. Reproducible research makes it easy to redo the experiments by inserting new data and applying it to a different problem.

C Interview Questions

**Question 6. How Many Data Structures Does R Language Have?**

**Answer :**

R language has Homogeneous and Heterogeneous data structures.

**Homogeneous data structures have same type of objects –** Vector, Matrix ad Array.

** Heterogeneous data structures have different type of objects –** Data frames and lists.

**Question 7. What Is The Process To Create A Table In R Language Without Using External Files?**

**Answer :**

MyTable= data.frame ()

edit (MyTable)

The above code will open an Excel Spreadsheet for entering data into MyTable.

Learn Data Science in R Programming to land a top gig as an Enterprise Data Scientist!

C Tutorial Hadoop Interview Questions

**Question 8. Explain About The Significance Of Transpose In R Language?**

**Answer :**

Transpose t () is the easiest method for reshaping the data before analysis.

**Question 9. What Are With () And By () Functions Used For?**

**Answer :**

With () function is used to apply an expression for a given dataset and BY () function is used for applying a function each level of factors.

Data modeling Interview Questions

**Question 10. Dplyr Package Is Used To Speed Up Data Frame Management Code. Which Package Can Be Integrated With Dplyr For Large Fast Tables?**

**Answer :**

data.table

Hadoop Tutorial

**Question 11. In Base Graphics System, Which Function Is Used To Add Elements To A Plot?**

**Answer :**

boxplot () or text ()

Apache Pig Interview Questions

**Question 12. What Are The Different Type Of Sorting Algorithms Available In R Language?**

**Answer :**

- Bucket Sort
- Selection Sort
- Quick Sort
- Bubble Sort
- Merge Sort

Data Mining Interview Questions

**Question 13. What Is The Command Used To Store R Objects In A File?**

**Answer :**

save (x, file=”x.Rdata”)

Apache Pig Tutorial

**Question 14. What Is The Best Way To Use Hadoop And R Together For Analysis?**

**Answer :**

HDFS can be used for storing the data for long-term. MapReduce jobs submitted from either Oozie, Pig or Hive can be used to encode, improve and sample the data sets from HDFS into R. This helps to leverage complex analysis tasks on the subset of data prepared in R.

**Question 15. What Will Be The Output Of Log (-5.8) When Executed On R Console?**

**Answer :**

Executing the above on R console will display a warning sign that NaN (Not a Number) will be produced because it is not possible to take the log of negative number.

Machine learning Interview Questions

**Question 16. How Is A Data Object Represented Internally In R Language?**

**Answer :**

unclass (as.Date (“2016-10-05″))

R Programming language Tutorial

**Question 17. Which Package In R Supports The Exploratory Analysis Of Genomic Data?**

**Answer :**

Adegenet.

Data analyst Interview Questions

**Question 18. What Is The Difference Between Data Frame And A Matrix In R?**

**Answer :**

Data frame can contain heterogeneous inputs while a matrix cannot. In matrix only similar data types can be stored whereas in a data frame there can be different data types like characters, integers or other data frames.

C Interview Questions

**Question 19. How Can You Add Datasets In R?**

**Answer :**

rbind () function can be used add datasets in R language provided the columns in the datasets should be same.

**Question 20. What Are Factor Variable In R Language?**

**Answer :**

Factor variables are categorical variables that hold either string or numeric values. Factor variables are used in various types of graphics and particularly for statistical modelling where the correct number of degrees of freedom is assigned to them.

R Programming language Interview Questions

**Question 21. What Is The Memory Limit In R?**

**Answer :**

8TB is the memory limit for 64-bit system memory and 3GB is the limit for 32-bit system memory.

**Question 22. What Are The Data Types In R On Which Binary Operators Can Be Applied?**

**Answer :**

Scalars, Matrices ad Vectors.

**Question 23. How Do You Create Log Linear Models In R Language?**

**Answer :**

Using the loglm () function

Advanced SAS Interview Questions

**Question 24. What Will Be The Class Of The Resulting Vector If You Concatenate A Number And Na?**

**Answer :**

number

Hadoop Interview Questions

**Question 25. What Is Meant By K-nearest Neighbour?**

**Answer :**

K-Nearest Neighbour is one of the simplest machine learning classification algorithms that is a subset of supervised learning based on lazy learning. In this algorithm the function is approximated locally and any computations are deferred until classification.

**Question 26. What Will Be The Class Of The Resulting Vector If You Concatenate A Number And A Character?**

**Answer :**

character

**Question 27. If You Want To Know All The Values In C (1, 3, 5, 7, 10) That Are Not In C (1, 5, 10, 12, 14). Which In-built Function In R Can Be Used To Do This? Also, How This Can Be Achieved Without Using The In-built Function?**

**Answer :**

Using in-built function – setdiff(c (1, 3, 5, 7, 10), c (1, 5, 10, 11, 13))

Without using in-built function – c (1, 3, 5, 7, 10) [! c (1, 3, 5, 7, 10) %in% c (1, 5, 10, 11, 13).

Data modeling Interview Questions

**Question 28. How Can You Debug And Test R Programming Code?**

**Answer :**

R code can be tested using Hadley’s testthat package.

**Question 29. What Will Be The Class Of The Resulting Vector If You Concatenate A Number And A Logical?**

**Answer :**

Number.

**Question 30. Write A Function In R Language To Replace The Missing Value In A Vector With The Mean Of That Vector?**

**Answer :**

mean impute <- function(x) {x [is.na(x)] <- mean(x, na.rm = TRUE); x}

**Question 31. What Happens If The Application Object Is Not Able To Handle An Event?**

**Answer :**

The event is dispatched to the delegate for processing.

**Question 32. Differentiate Between Lapply And Sapply?**

**Answer :**

If the programmers want the output to be a data frame or a vector, then sapply function is used whereas if a programmer wants the output to be a list then lapply is used. There one more function known as vapply which is preferred over sapply as vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is difficult to be implemented and more verbose.

**Question 33. Differentiate Between Seq (6) And Seq_along (6)?**

**Answer :**

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

Apache Pig Interview Questions

**Question 34. How Will You Read A .csv File In R Language?**

**Answer :**

read.csv () function is used to read a .csv fi

le in R language.

**Below is a simple example –**

filcontent

print (filecontent)

**Question 35. How Do You Write R Commands?**

**Answer :**

The line of code in R language should begin with a hash symbol (#).

**Question 36. How Can You Verify If A Given Object “x” Is A Matric Data Object?**

**Answer :**

If the function call is.matrix(X ) returns TRUE then X can be termed as a matrix data object.

Machine learning Interview Questions

**Question 37. What Do You Understand By Element Recycling In R?**

**Answer :**

If two vectors with different lengths perform an operation –the elements of the shorter vector will be re-used to complete the operation. This is referred to as element recycling.

Example – Vector A <-c(1,2,0,4) and Vector B<-(3,6) then the result of A*B will be ( 3,12,0,24). Here 3 and 6 of vector B are repeated when computing the result.

**Question 38. How Can You Verify If A Given Object “x” Is A Matrix Data Object?**

**Answer :**

If the function call is.matrix(X) returns true then X can be considered as a matrix data object otheriwse not.

**Question 39. How Will You Measure The Probability Of A Binary Response Variable In R Language?**

**Answer :**

Logistic regression can be used for this and the function glm () in R language provides this functionality.

**Question 40. What Is The Use Of Sample And Subset Functions In R Programming Language?**

**Answer :**

- Sample () function can be used to select a random sample of size ‘n’ from a huge dataset.
- Subset () function is used to select variables and observations from a given dataset.

Data analyst Interview Questions

**Question 41. How Can You Resample Statistical Tests In R Language?**

**Answer :**

Coin package in R provides various options for re-randomization and permutations based on statistical tests. When test assumptions cannot be met then this package serves as the best alternative to classical methods as it does not assume random sampling from well-defined populations.

**Question 42. What Is The Purpose Of Using Next Statement In R Language?**

**Answer :**

If a developer wants to skip the current iteration of a loop in the code without terminating it then they can use the next statement. Whenever the R parser comes across the next statement in the code, it skips evaluation of the loop further and jumps to the next iteration of the loop.

R Programming language Interview Questions

**Question 43. How Will You Create Scatter Plot Matrices In R Language?**

**Answer :**

A matrix of scatter plots can be produced using pairs. Pairs function takes various parameters like formula, data, subset, labels, etc.

**The two key parameters required to build a scatter plot matrix are –**

**formula-** A formula basically like ~a+b+c . Each term gives a separate variable in the pairs plots where the terms should be numerical vectors. It basically represents the series of variables used in pairs.

**data-** It basically represents the dataset from which the variables have to be taken for building a scatterplot.

**Question 44. How Will You Check If An Element 25 Is Present In A Vector?**

**Answer :**

**There are various ways to do this**–

- It can be done using the match () function- match () function returns the first appearance of a particular element.
- The other is to use %in% which returns a Boolean value either true or false.
- Is.element () function also returns a Boolean value either true or false based on whether it is present in a vector or not.

**Question 45. What Is The Difference Between Library() And Require() Functions In R Language?**

**Answer :**

There is no real difference between the two if the packages are not being loaded inside the function. require () function is usually used inside function and throws a warning whenever a particular package is not found. On the flip side, library () function gives an error message if the desired package cannot be loaded.

**Question 46. What Are The Rules To Define A Variable Name In R Programming Language?**

**Answer :**

A variable name in R programming language can contain numeric and alphabets along with special characters like dot (.) and underline (-). Variable names in R language can begin with an alphabet or the dot symbol. However, if the variable name begins with a dot symbol it should not be a followed by a numeric digit.

**Question 47. What Do You Understand By A Workspace In R Programming Language?**

**Answer :**

The current R working environment of a user that has user defined objects like lists, vectors, etc. is referred to as Workspace in R language.

**Question 48. Which Function Helps You Perform Sorting In R Language?**

**Answer :**

Order ()

**Question 49. How Will You List All The Data Sets Available In All R Packages?**

**Answer :**

**Using the below line of code-**

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

**Question 50. Which Function Is Used To Create A Histogram Visualisation In R Programming Language?**

**Answer :**

Hist()

**Question 51. Write The Syntax To Set The Path For Current Working Directory In R Environment?**

**Answer :**

Setwd(“dir_path”)

**Question 52. What Will Be The Output Of Runif (7)?**

**Answer :**

It will generate 7 random numbers between 0 and 1.

**Question 53. What Is The Difference Between Rnorm And Runif Functions?**

**Answer :**

rnorm function generates “n” normal random numbers based on the mean and standard deviation arguments passed to the function.

**Syntax of rnorm function –**

rnorm(n, mean = , sd = )

runif function generates “n” unform random numbers in the interval of minimum and maximum values passed to the function.

**Syntax of runif function –**

runif(n, min = , max = )

**Question 54. What Will Be The Output On Executing The Following R Programming Code ?**

**Answer :**

mat<-matrix(rep(c(TRUE,FALSE),8),nrow=4)

sum(mat)

8

**Question 55. How Will You Combine Multiple Different String Like “data”, “science”, “in” ,“r”, “programming” As A Single String “data_science_in_r_programmming” ?**

**Answer :**

paste(“Data”, “Science”, “in” ,“R”, “Programming”,sep=”_”)

**Question 56. Write A Function To Extract The First Name From The String “mr. Tom White”?**

**Answer :**

substr (“Mr. Tom White”,start=5, stop=7)

**Question 57. Can You Tell If The Equation Given Below Is Linear Or Not ?**

**Answer :**

Emp_sal= 2000+2.5(emp_age)2

Yes it is a linear equation as the coefficients are linear.

**Question 58. What Is R Base Package?**

**Answer :**

R Base package is the package that is loaded by default whenever R programming environent is loaded .R base package provides basic fucntionalites in R environment like arithmetic calcualtions, input/output.

**Question 59. How Will You Merge Two Dataframes In R Programming Language?**

**Answer :**

Merge () function is used to combine two dataframes and it identifies common rows or columns between the 2 dataframes. Merge () function basically finds the intersection between two different sets of data.

**Merge () function in R language takes a long list of arguments as follows –**

**Syntax for using Merge function in R language –**

merge (x, y, by.x, by.y, all.x or all.y or all )

X represents the first dataframe.

Y represents the second dataframe.

**by.X-** Variable name in dataframe X that is common in Y.

**by.Y-** Variable name in dataframe Y that is common in X.

**all.x –** It is a logical value that specifies the type of merge. all.X should be set to true, if we want all the observations from dataframe X . This results in Left Join.

**all.y –** It is a logical value that specifies the type of merge. all.y should be set to true , if we want all the observations from dataframe Y . This results in Right Join.

**all –** The default value for this is set to FALSE which means that only matching rows are returned resulting in Inner join. This should be set to true if you want all the observations from dataframe X and Y resulting in Outer join.

**Question 60. What Will Be The Result Of Multiplying Two Vectors In R Having Different Lengths?**

**Answer :**

The multiplication of the two vectors will be performed and the output will be displayed with a warning message like – “Longer object length is not a multiple of shorter object length.” Suppose there is a vector a<-c (1, 2, 3) and vector b <- (2, 3) then the multiplication of the vectors a*b will give the resultant as 2 6 6 with the warning message. The multiplication is performed in a sequential manner but since the length is not same, the first element of the smaller vector b will be multiplied with the last element of the larger vector a.

**Question 61. R Programming Language Has Several Packages For Data Science Which Are Meant To Solve A Specific Problem, How Do You Decide Which One To Use?**

**Answer :**

CRAN package repository in R has more than 6000 packages, so a data scientist needs to follow a well-defined process and criteria to select the right one for a specific task. When looking for a package in the CRAN repository a data scientist should list out all the requirements and issues so that an ideal R package can address all those needs and issues.

The best way to answer this question is to look for an R package that follows good software development principles and practices. For example, you might want to look at the quality documentation and unit tests. The next step is to check out how a particular R package is used and read the reviews posted by other users of the R package. It is important to know if other data scientists or data analysts have been able to solve a similar problem as that of yours. When you in doubt choosing a particular R package, I would always ask for feedback from R community members or other colleagues to ensure that I am making the right choice.

**Question 62. How Can You Merge Two Data Frames In R Language?**

**Answer :**

Data frames in R language can be merged manually using cbind () functions or by using the merge () function on common rows or columns.

**Question 63. Explain The Usage Of Which() Function In R Language?**

**Answer :**

which() function determines the position of elements in a logical vector that are TRUE. In the below example, we are finding the row number wherein the maximum value of variable v1 is recorded.

mydata=data.frame(v1 = c(2,4,12,3,6))

which(mydata$v1==max(mydata$v1))

It returns 3 as 12 is the maximum value and it is at 3rd row in the variable x=v1.

**Question 64. How Will You Convert A Factor Variable To Numeric In R Language ?**

**Answer :**

A factor variable can be converted to numeric using the as.numeric() function in R language. However, the variable first needs to be converted to character before being converted to numberic because the as.numeric() function in R does not return original values but returns the vector of the levels of the factor variable.

X <- factor(c(4, 5, 6, 6, 4))

X1 = as.numeric(as.character(X))