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
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
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
Explanation: new <- old[n1:n2,n3:n4] select the n1 through n2 rows of variables n3 through n4.
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
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
Explanation: cummax() function returns the cumulative maxima.
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
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
Explanation: as.integer for object of class truncates decimal part of image values and then converts to type integer.
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
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
Explanation: all(x%in%y) returns true if x is a proper subset of y.
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
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.
- Check Information Technology Books
- Practice Programming MCQs
- Apply for R Programming Internship
- Check R Programming Books
- Apply for Programming Internship