Data Science Interview Questions and Answers Set 6

51. What are the rules to define a variable name in R programming language?

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.

52. What do you understand by a workspace in R programming 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.

53. Which function helps you perform sorting in R language?

Order ()

54. How will you list all the data sets available in all R packages?

Using the below line of code-
data(package = .packages(all.available = TRUE))

55. Which function is used to create a histogram visualisation in R programming language?

Hist()

DATA SCIENCE TRAINING
Weekend / Weekday Batch


56. Write the syntax to set the path for current working directory in R environment?

Setwd(“dir_path”)

57. How will you drop variables using indices in a data frame?

Let’s take a dataframe df<-data.frame(v1=c(1:5),v2=c(2:6),v3=c(3:7),v4=c(4:8))

df

## v1 v2 v3 v4

## 1 1 2 3 4
## 2 2 3 4 5
## 3 3 4 5 6
## 4 4 5 6 7
## 5 5 6 7 8

Suppose we want to drop variables v2 & v3 , the variables v2 and v3 can be dropped using negative indicies as follows-

df1<-df[-c(2,3)]

df1

## v1 v4

## 1 1 4

## 2 2 5

## 3 3 6

## 4 4 7

## 5 5 8

58. What will be the output of runif (7)?

It will generate 7 randowm numbers between 0 and 1.

59. What is the difference between rnorm and runif functions ?

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 = )

60. What will be the output on executing the following

R programming code – mat<-matrix(rep(c(TRUE,FALSE),8),nrow=4)

sum(mat)

8