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

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)

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]

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)

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)

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)

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)

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

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

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)
c) fivenum(x, na.rm=TRUE)
d) var(x, na.rm=TRUE)

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.