R Basics | Fresco Play
Question 1: Which function is used to generate Sequences in R?
Answer: seq()
Question 2: Which of the following while loops will print numbers from 1 to 4?
Answer: x<-1 while(x < 5) { print(x); x <- x+1;}
Question 3: What is the output of the R code: m <- c(1, 2, 3) n <- c(6, 5, 4) (m < 2) & (n > 5)
Answer: TRUE FALSE FALSE
Question 4: If I have two vectors, x<-c(1,3,5) and y<-c(3,2,10), what does rbind(x,y) give ?
Answer: A 2 x 3 matrix
Question 5: Which of the following statements is correct?
Answer: All the options
Question 6: What is the function in R to get the # of observations in a data frame ?
Answer: nrow()
Question 7: What would be the result of following code: x <- 0:4 as.logical(x)
Answer: FALSE TRUE TRUE TRUE TRUE
Question 8: In R, the following are all atomic data types except
Answer: Data frame
Question 9: Suppose I have a vector x <- c(3,5,1,10,12,6) and I want to set all elements of this vector that are less than 6 to be equal to zero, what R code achieves this ?
Answer: x[x<6]<-0
Question 10: What is the class of the object defined by the expression x<- c(4,"a",TRUE) in R ?
Answer: Character
Question 11: Which of the following statements is correct?
Answer: Number Inf represents infinity in R
Question 12: Which function can be used to create collection of vectors objects?
Answer: c()
Question 13: What would be the result of following code: x <- 4 class(x)
Answer: numeric
Question 14: A key property of vectors in R is that
Answer: All elements must be of the same class
Question 15: What would be the output of the following code ? x <- c("a", "b", "c", "c", "d", "a") x[c(1, 3, 4)]
Answer: "a" "c" "c"
Question 16: Which of the following statements is correct?
Answer: All the options
Question 17: Which R command creates a 2 by 2 matrix with the values 1,2,3 and 4?
Answer: m <- matrix(1:4, 2, 2)
Question 18: What would be the result of following code: x <- c("x", "y", "z") as.logical(x)
Answer: 1. NaN NaN NaN 2. "x" "y" "z"
Question 19: What command will you enter in the R console to get help on how to quit R
Answer: help(q)
Question 20: Which command allows you to get the median tree Height of the R sample dataset "trees"?
Answer: median(trees$Height)
Post a comment
Get your FREE PDF on "100 Ways to Try ChatGPT Today"
Generating link, please wait for: 60 seconds
Comments
Join the conversation and share your thoughts! Leave the first comment.