Professional Documents
Culture Documents
Top 100 R Interview Questions and Answers For 2021
Top 100 R Interview Questions and Answers For 2021
html
HOME SAS R PYTHON DATA SCIENCE CREDIT RISK SQL EXCEL SPSS
INFOGRAPHICS
SEARCH... GO
Home » R Interview Questions » Top 100 R Interview Questions and Answers for 2021 Get Free
Email Updates
1 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
2 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
x <- factor(1:5)
class(x)
It returns factor.
Object Class
Example 2 :
xx <- data.frame(var1=c(1:5))
class(xx)
It returns "data.frame".
✖
Love this post?returns 'data.frame'
Support Us! : 5 obs. of
3 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
x <- factor(1:5)
mode(x)
Mode Function
x <- data.frame(var1=c(1:5))
mode(x)
It returns list.
✖
special
Love this post? data structure
Support Us! called "factor" to store
rical variables. It tells R that a variable is
al or ordinal by making it a factor.
4 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
gender = c(1,2,1,2,1,2)
gender = factor(gender)
gender
gender = factor(c("m","f","f","m","f","f"))
table(gender)
Output
t = data.frame(table(gender))
✖
Love this post? Support Us!
t$percent= round(t$Freq /
5 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
Frequency Distribution
gender = factor(c("m","f","f","m","f","f"))
x = table(gender)
cumsum(x)
Cumulative Sum
✖
Love this post? Support Us!
6 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
t = data.frame(table(gender))
t$cumfreq = cumsum(t$Freq)
t$cumpercent= round(t$cumfreq /
sum(t$Freq)*100,2)
df = sample(1:100, 25)
hist(df, right=FALSE)
✖
Love this post? Support Us!
7 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
sample(LETTERS[1:5],16,replace =
8 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
TRUE)
mydata.count= table(mydata)
barplot(mydata.count)
To improve the layout of bar graph, you can use the code
below:
✖
Love this post? Support Us!
alculate the frequency distribution with table
9 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
mydata =
sample(LETTERS[1:5],16,replace =
TRUE)
mydata.count= table(mydata)
pie(mydata.count, col=rainbow(12))
x <- c(4,5,6)
y <- c(2,3) ✖
Love this post? Support Us!
10 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
Multiplication of vectors
x <- c(4,5,6,7)
✖
Love this post? Support Us!
11 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
1. Vector
2. Matrix
3. Array
4. List
5. Data frame
�. Factor
✖
Love thisopost? Support
combine Us!
data frames?
12 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
x = c(1:5)
y = c("m","f","f","m","f")
z=cbind(x,y)
cbind : Output
z = rbind(x,y)
✖
Love this post? Support Us!
rbind : Output
13 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
df = data.frame(x = c(1:4), y =
c("m","f","f","m"))
df2 = data.frame(x = c(5:8))
✖
Love this post? Support Us!
14 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
library(dplyr)
combdf = bind_rows(df,df2)
15 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
14. What is the use of with() and by() functions? What are
its alternatives?
df=data.frame(x=c(1:6),
y=c(1,2,4,6,8,12))
16 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
library(dplyr)
df %>% mutate((x+y) + (x-y))
by() function in R
✖
Love this post? Support Us!
data.frame(var1=factor(c(1,2,1,2,1,2)),
17 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
var2=c(10:15))
with(df, by(df, var1, function(x)
mean(x$var2)))
library(dplyr)
df %>% group_by(var1)%>%
summarise(mean(var2))
df = data.frame(var1=c(1:5))
colnames(df)[colnames(df) == 'var1']
<- 'variable1'
18 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
mydata=data.frame(x = c(1,3,10,5,7))
which(mydata$x==max(mydata$x))
19 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
NA 1 5
3 NA 2
", header=TRUE)
library(dplyr)
data %>% mutate(var=coalesce(X,Y,Z))
COALESCE Function in R
dt1 = read.table(text="
XYZ
7 NA 5
245
✖
Love this post? Support Us!
20 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
Output
dt2 = read.table(text="
ABC
800
605
", header=TRUE)
21 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
ifelse(df$var1==NA, 0,1)
x=3
mult <- function(j)
{
x=j*2
return(x)
}
mult(2)
[1] 4
✖
Love this post? Support Us!
Output
22 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
x=3
mult <- function(j)
{
x <<- j * 2
return(x)
}
mult(2)
x
✖
Love this post? Support Us!
a <- factor(c(5, 6, 7, 7, 5))
a1 = as.numeric(as.character(a))
23 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
✖
Love this post? Support Us!
24 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
a = "Deepanshu"
b = "Bhalla"
paste(a, b)
x = "AXZ2016"
substr(x,1,3) ✖
Love this post? Support Us!
25 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
dt2 = read.table(text="
var
Sandy,Jones
Dave,Jon,Jhonson
", header=TRUE)
library(stringr)
dt2$var2 = word(dt2$var, -1, sep = ",")
26 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
df1=data.frame(ID=c(1:5),
Score=runif(5,50,100))
df2=data.frame(ID=c(3,5,7:9),
✖
Love this post? Support Us!
Score2=runif(5,1,100))
merge(df1, df2, by ="ID", all.x
27 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
= TRUE)
library(sqldf)
comb = sqldf('select df1.*, df2.* from
df1 left join df2 on df1.ID = df2.ID')
library(dplyr)
comb = left_join(df1, df2, by = "ID")
28 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
comb = merge(df1,df2,by=NULL)
library(sqldf)
comb2 = sqldf('select * from df1 join
df2 ')
df1=data.frame(ID=c(1:5), Score=c(50:54))
df2=data.frame(ID=c(3,5,7:9), Score=c(52,60:63))
library(dplyr)
comb = intersect(df1,df2)
library(sqldf)
comb2 = sqldf('select * from df1
intersect select * from
✖ df2 ')
Love this post? Support Us!
29 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
R Base Method
✖
Love this post? Support Us!
30 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
library(tictoc)
tic()
runif(5555,1,1000)
toc()
# Load data
library(nyc�ights13)
data(�ights)
df = setDT(�ights)
31 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
32 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
library(data.table)
yyy = fread("C:\\Users\\Dave
\\Example.csv", header = TRUE)
1. temp = data.frame(v1<-c(1:10),v2<-c(5:14))
2. temp = data.frame(v1=c(1:10),v2=c(5:14))
rm(list=ls())
✖
Love this post? Support Us!
are the various sorting algorithms in R?
33 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
1. Bubble Sort
2. Selection Sort
3. Merge Sort
4. Quick Sort
5. Bucket Sort
mydata = data.frame(score =
ifelse(sign(rnorm(25))==-1,1,2),
experience= sample(1:25))
R Base Method
mydata1 <-
✖
Love this post? Support Us!
mydata[order(mydata$score,
-mydata$experience),]
34 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
library(dplyr)
mydata1 = arrange(mydata, score,
desc(experience))
R Base Method
library(dplyr)
df = select(mydata, -c(x,y,z))
✖
Love thisopost?
save everything in R session
Support Us!
35 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
save.image(�le="dt.RData")
df <- na.omit(mydata)
data = data.frame(y=sample(1:25,
replace = TRUE), x=rnorm(25))
✖
Love this post? Support Us!
36 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
test = subset(data,
!duplicated(data[,"y"]))
dplyr Method
library(dplyr)
test1 = distinct(data, y, .keep_all=
TRUE)
✖
Love this post? Support Us!
dates <- as.Date(c("2015-09-02",
37 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
library(lubridate)
interval(dates[1], dates[2]) %/%
hours(1)
interval(dates[1], dates[2]) %/%
days(1)
interval(dates[1], dates[2]) %/%
weeks(1)
interval(dates[1], dates[2]) %/%
months(1)
interval(dates[1], dates[2]) %/%
years(1)
✖
mber
Love this of months
post? Supportunit
Us! is not included in the
ifftime() function so we can use interval()
n of lubridate() package.
38 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
day(mydate)
month(mydate)
year(mydate)
hour(mydate)
minute(mydate) ✖
Love this post? Support Us!
39 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
1. For Loop
2. While Loop
40 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
set.seed(1234)
x = sample(1:50, 10)
x
[1] 6 31 30 48 40 29 1 10 28 22
sort(x)
[1] 1 6 10 22 28 29 30 31 40 48
rank(x)
[1] 2 8 7 10 9 6 1 3 5 4
order(x)
[1] 7 1 8 10 9 6 3 2 5 4
41 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
42 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
model?
43 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
durbinWatsonTest() function
dt = sort(sample(nrow(mydata),
nrow(mydata)*.7))
train<-mydata[dt,] ✖
Love this post? Support Us!
44 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
data2 = scale(data)
rpart, party
cor() function
✖
Love this post? Support Us!
you heard 'relaimpo' package?
45 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
✖
xph()
Love this function
post? of survival
Support Us! package.
46 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
arules package
Subscribe
Related Posts
About Author:
Deepanshu founded ListenData with a simple objective - Make analytics
easy to understand and follow. He has over 10 years of experience in data
science. During his tenure, he has worked with global clients in various
✖
domains Us!
Love this post? Support like Banking, Insurance, Private Equity, Telecom and Human
While I love having friends who agree, I only learn from those who don't
47 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
Reply
Replies
Reply
Reply
Replies
Reply
Awesome!
✖
Love this post? Support Us!
48 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
I see many times refering to dplyr package. How relevant may it be? I
never use it, there is nothing on dplyr that I cannot do with R-base
functions, and I dont like it...
Reply
Reply
Reply
Thank you for sharing great list of data science interview questions
and answers. I am looking for more question and answer.
Reply
Thank you sir it's amazing tutorial for freshers and experienced
Reply
Reply
Reply
✖
Love this post? Support Us!
49 of 50 09-07-2021, 02:08
Top 100 R Interview Questions and Answers for 2021 https://www.listendata.com/2016/09/r-interview-questions-and-answers.html
Reply
Reply
← PREV NEXT →
✖
Love this post? Support Us!
50 of 50 09-07-2021, 02:08