R Programming Questions and Answers – Commands – 2

This set of tricky R Programming questions and answers focuses on “Commands – 2”.

1. Which of the following code will drop the nth column?
a) new <- old[-n,]

b) new <- old[,-n]

c) new <- old[,-c(i,j)]

d) new <- subset(old,logical)
View Answer

Answer: a
Explanation: new <- old[-n,] drops the nth row.

2. Which of the following code drop the ith and jth column?
a) new <- old[-n,]

b) new <- old[,-n]

c) new <- old[,-c(i,j)]

d) new <- subset(old,logical)
View Answer

Answer: c
Explanation: new <- subset(old,logical) select those cases that meet the logical condition.

3. Which of the following statement find cases with no missing values?
a) complete <- subset(data.df,complete.cases(data.df)
b) complete <- sub(data.df,complete.cases(data.df)
c) complete <- subset(data.df,completeall.cases(data.df)
d) new <- old[n1:n2,n3:n4]

View Answer

Answer: a
Explanation: new <- old[n1:n2,n3:n4] select the n1 through n2 rows of variables n3 through n4.

advertisement
advertisement

4. Which of the following statement is normal distribution?
a) dnorm(x, mean=0, sd=1, log = FALSE)
b) pnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE)
c) qnorm(p, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE)
d) rnorm(n, mean=0, sd=1)
View Answer

Answer: a
Explanation: d stands for density.

5. which of the following statement gives cumulative sum?
a) cumsum(x,na=rm=TRUE)
b) cumprod(x)
c) cummax(x)
d) cummin(x)
View Answer

Answer: a
Explanation: cummax() function returns the cumulative maxima.

Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of the following is uniform distribution?
a) dunif(x, min=0, max=1, log = FALSE)
b) punif(q, min=0, max=1, lower.tail = TRUE, log.p = FALSE)
c) qunif(p, min=0, max=1, lower.tail = TRUE, log.p = FALSE)
d) runif(n, min=0, max=1)
View Answer

Answer: a
Explanation: These functions provide information about the uniform distribution on the interval from min to max.

7. Which of the following truncates real x to integers?
a) as.order(x)
b) as.integer(x)
c) as.numeric(x)
d) as.character(x)
View Answer

Answer: b
Explanation: as.integer for object of class truncates decimal part of image values and then converts to type integer.

advertisement

8. Which of the following tests each element of x for membership in y?
a) y%in%x
b) all(x)
c) any(x)
d) x%in%y
View Answer

Answer: d
Explanation: y%in%x tests each element of y for membership in x. x%in%y tests each element of x for membership in y.

9. Which of the following finds the maximum value in the vector x, exclude missing values?
a) rm(x)
b) max(x, na.rm=TRUE)
c) all(x)
d) x%in%y
View Answer

Answer: b
Explanation: all(x%in%y) returns true if x is a proper subset of y.

advertisement

10. Which of the following produces the variance covariance matrix?
a) sd(x, na.rm=TRUE)
b) mad(x, na.rm=TRUE)
c) fivenum(x, na.rm=TRUE)
d) var(x, na.rm=TRUE)
View Answer

Answer: d
Explanation: mad(x, na.rm=TRUE) gives median absolute deviation.var(y) instructs R to calculate the sample variance of Y. In other words it uses n-1 ‘degrees of freedom’, where n is the number of observations in Y.sd(y) instructs R to return the sample standard deviation of y, using n-1 degrees of freedom.

Sanfoundry Global Education & Learning Series – R Programming Language.

Here’s the list of Best Books in R Programming Language.

To practice tricky questions on all areas of R Programming, Here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.