R Programming Interview Questions-2
R Programming Interview Questions-2
Which
of the following command will combine "Male" and "Female" column into a
single column named "Sex" and create another variable named "Count" as the
count of male or female "Name" wise.
Initial dataframe
Name Male Female
A 1 6
B 5 9
Output Dataframe
Name Sex Count
A Male 1
B Male 5
A Female 6
B Female 9
dmCQmCieac2OT 8ZMHFKE2KIIK
collect(dataframe,Male:Female,Sex,Count)
gather(dataframe,Sex,Count,-Name)
gather(dataframe,Sex,Count)
collect(dataframe,Male:Female,Sex,Count,-Name)
Q 32) The dataframe below contains one category of messy data where
multiple columns are stacked into one column which is highly undesirable.
Sex_Class Count
Male_1 1
Male_2 2
Female_1 3
Female_2 4
Which of the following code will convert the above dataframe to the
dataframe below ? The dataframe is stored in a variable named "dataframe".
Male 1 1
Male 2 2
Female 1 3
Female 2 4
dmCQmCieac2OT FJ 2G12UGL7VG
separate(dataframe,Sex_Class,c("Sex","Class"))
split(dataframe,Sex_Class,c("Sex","Class"))
disjoint(dataframe,Sex_Class,c("Sex","Class"))
Alaska 1 Mid A
Alaska 1 Final B
Banta 2 Mid A
Banta 2 Final A
Which of the following code will convert the above dataset into the one shown
below?
Alaska 1 A B
Banta 2 A A
dmCQmCieac2OT 5NPDUE18ARVF
transform(dataframe,unique(Term),Grade)
spread(dataframe,Term,Grade)
copy()
paste()
bind()
Character strings are entered using either matching double or single quote.
dmCQmCieac2OT BQ1P7W4T72KY
rep()
data()
view()
quantile()
barplot()
barchart()
table()
stem()
xtabs()
Hello, world!
14
Hello, world!/n
14
Hello, world!
13
Hello, world!/n
13
Q 41) Which is the missing metric from running the quantile function on a
numeric vector in comparison to running the summary function on the same
vector?
dmCQmCieac2OT 3Z0K3PA82QQD
Median
Mean
Maximum
Minimum
Q 42) Which of the following command will plot a blue boxplot of a numeric
vector named "vec"?
dmCQmCieac2OT 75SB61XVVNW7
boxplot(vec,col="blue")
boxplot(vec,color="blue")
boxplot(vec,color="BLUE")
Q 43) Which of the following command will create a histogram with 100
buckets of data ?
dmCQmCieac2OT XCGBO23GAVU0
hist(vec,buckets=100)
hist(vec,into=100)
hist(vec,breaks=100)
y-axis label
A B
12 East
15 West
13 East
15 East
14 West
We wish to create a boxplot in a single line of code per "B" i.e a total of two
boxplots (one for East and one for West). Which of the following command will
achieve the purpose?
dmCQmCieac2OT T1SUDY0Z32ZF
boxplot(A~B,data=sam)
boxplot(A,B,data=sam)
boxplot(A|B,data=sam)
Q 46) Which of the following command will split the plotting window into 3 X 4
sub windows and where the plots enter the window row wise.
dmCQmCieac2OT 90J WLVKN1HIN
par(split=c(3,4))
par(mfcol=c(3,4))
par(mfrow=c(3,4))
par(col=c(3,4))
Q 47) A dataframe named "frame" contains two numerical columns named "A"
and "B". Which of the following command will draw a scatter plot between the
two columns of the dataframe?
dmCQmCieac2OT 63YZ94AWN2UL
with(frame,plot(A,B))
plot(frame$A,frame$B)
A B C
15 42 East
11 31 West
56 54 East
45 63 East
12 26 West
Which of the following command will draw a scatter plot between "A" and "B"
differentiated by different color of "C" like the one below.
dmCQmCieac2OT I0PQLAX4W493
plot(frame$A,frame$B,col=frame$C)
with(frame,plot(A,B,col=C)
1 and 2
Q 49) Which of the following does not apply to R’s base plotting system ?
dmCQmCieac2OT AX13AHI9E7OP
Can easily go back once the plot has started (eg: to change margins etc).
It is convenient and mirrors how we think of building plots and analysing data
qplot
gplot
plot
xyplot
Q 51) What is true regarding the relation between the number of plots drawn
by 'facet_wrap" and "facet_grid" ?
dmCQmCieac2OT AQ1XVMAOFBZ2
facet_wrap>facet_grid
facet_wrap<facet_grid
facet_wrap<= facet_grid
coordinate_flip
coord_flip
coordinate_rotate
coord_rotate
A B
Alpha 100
Beta 120
Gamma 80
Delta 110
Which of the following command will create a bar plot for the above dataset
with the values in column "B" being the height of the bar?"
dmCQmCieac2OT KB9TGAE0GOKV
ggplot(frame,aes(A,B))+geom_bar(stat="identity")
ggplot(frame,aes(A,B))+geom_bar(stat="bin")
ggplot(frame,aes(A,B))+geom_bar()
We wish to create a stacked bar chart for "cyl" variable with stacking criteria
being "vs" variable. Which of the following command will help us do this ?
dmCQmCieac2OT 5S7SUCBMU8D7
qplot(factor(cyl),data=frame,geom="bar",fill=factor(vs))
ggplot(mtcars,aes(factor(cyl),fill=factor(vs)))+geom_bar()
Both 1 and 2
Q 55) The question is same as previous one . The only difference is that you
have to create a dodged bar chart instead of a stacked one. Which of the
following command will help us do that ?
dmCQmCieac2OT VJ MYK0ZRFRKX
qplot(factor(cyl),data=frame,geom="bar",fill=factor(vs),position="dodge")
ggplot(mtcars,aes(factor(cyl),fill=factor(vs)))+geom_bar(position="dodge")