This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
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)) 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)) |
|
| 2. |
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. 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. |
|
| 3. |
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. Data frames in R language can be merged manually using cbind () functions or by using the merge () function on common rows or columns. |
|
| 4. |
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. 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. |
|
| 5. |
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. 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. |
|
| 6. |
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. 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. |
|
| 7. |
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. 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. |
|
| 8. |
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. Emp_sal= 2000+2.5(emp_age)2 Yes it is a linear equation as the coefficients are linear. |
|
| 9. |
Write A Function To Extract The First Name From The String “mr. Tom White”? |
|
Answer» SUBSTR (“MR. TOM WHITE”,start=5, stop=7) substr (“Mr. Tom White”,start=5, stop=7) |
|
| 10. |
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="_") paste(“Data”, “Science”, “in” ,“R”, “Programming”,sep="_") |
|
| 11. |
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 mat<-matrix(rep(c(TRUE,FALSE),8),nrow=4) sum(mat) 8 |
|
| 12. |
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 - 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 = ) |
|
| 13. |
What Will Be The Output Of Runif (7)? |
|
Answer» It will GENERATE 7 RANDOM numbers between 0 and 1. It will generate 7 random numbers between 0 and 1. |
|
| 14. |
Write The Syntax To Set The Path For Current Working Directory In R Environment? |
|
Answer» Setwd(“dir_path”) Setwd(“dir_path”) |
|
| 15. |
Which Function Is Used To Create A Histogram Visualisation In R Programming Language? |
|
Answer» HIST() Hist() |
|
| 16. |
How Will You List All The Data Sets Available In All R Packages? |
|
Answer»
data(package = .PACKAGES(all.available = TRUE)) Using the below line of code- data(package = .packages(all.available = TRUE)) |
|
| 17. |
Which Function Helps You Perform Sorting In R Language? |
|
Answer» ORDER () Order () |
|
| 18. |
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. 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. |
|
| 19. |
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. 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. |
|
| 20. |
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. 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. |
|
| 21. |
How Will You Check If An Element 25 Is Present In A Vector? |
|
Answer» There are various ways to do this-
There are various ways to do this- |
|
| 22. |
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. 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. |
|
| 23. |
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. 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. |
|
| 24. |
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. 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. |
|
| 25. |
What Is The Use Of Sample And Subset Functions In R Programming Language? |
| Answer» | |
| 26. |
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. Logistic regression can be used for this and the function glm () in R language provides this functionality. |
|
| 27. |
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. If the function call is.matrix(X) returns true then X can be considered as a matrix data object otheriwse not. |
|
| 28. |
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. 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. |
|
| 29. |
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. If the function call is.matrix(X ) returns TRUE then X can be termed as a matrix data object. |
|
| 30. |
How Do You Write R Commands? |
|
Answer» The LINE of code in R LANGUAGE should BEGIN with a HASH symbol (#). The line of code in R language should begin with a hash symbol (#). |
|
| 31. |
How Will You Read A .csv File In R Language? |
|
Answer» read.CSV () FUNCTION is used to read a .csv file in R language. Below is a SIMPLE example – filcontent print (filecontent) read.csv () function is used to read a .csv file in R language. Below is a simple example – filcontent print (filecontent) |
|
| 32. |
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)). 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)). |
|
| 33. |
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. 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. |
|
| 34. |
What Happens If The Application Object Is Not Able To Handle An Event? |
|
Answer» The EVENT is DISPATCHED to the DELEGATE for PROCESSING. The event is dispatched to the delegate for processing. |
|
| 35. |
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} mean impute <- function(x) {x [is.na(x)] <- mean(x, na.rm = TRUE); x} |
|
| 36. |
What Will Be The Class Of The Resulting Vector If You Concatenate A Number And A Logical? |
|
Answer» Number. Number. |
|
| 37. |
How Can You Debug And Test R Programming Code? |
|
Answer» R CODE can be tested USING Hadley’s testthat PACKAGE. R code can be tested using Hadley’s testthat package. |
|
| 38. |
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). 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). |
|
| 39. |
What Will Be The Class Of The Resulting Vector If You Concatenate A Number And A Character? |
|
Answer» character character |
|
| 40. |
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. 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. |
|
| 41. |
What Will Be The Class Of The Resulting Vector If You Concatenate A Number And Na? |
|
Answer» number number |
|
| 42. |
How Do You Create Log Linear Models In R Language? |
|
Answer» Using the loglm () function |
|
| 43. |
What Are The Data Types In R On Which Binary Operators Can Be Applied? |
|
Answer» Scalars, Matrices ad Vectors. |
|
| 44. |
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. 8TB is the memory limit for 64-bit system memory and 3GB is the limit for 32-bit system memory. |
|
| 45. |
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. 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. |
|
| 46. |
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. rbind () function can be used add datasets in R language provided the columns in the datasets should be same. |
|
| 47. |
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. 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. |
|
| 48. |
Which Package In R Supports The Exploratory Analysis Of Genomic Data? |
|
Answer» Adegenet. Adegenet. |
|
| 49. |
How Is A Data Object Represented Internally In R Language? |
|
Answer» UNCLASS (as.Date (“2016-10-05″)) unclass (as.Date (“2016-10-05″)) |
|
| 50. |
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. 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. |
|