Q. What function is used to convert a factor to a character vector in R?

  • (A) as.factor()
  • (B) as.character()
  • (C) to.character()
  • (D) factor_to_char()
πŸ’¬ Discuss
βœ… Correct Answer: (B) as.character()

Q. How is a data frame column named Age selected in R?

  • (A) data$Age
  • (B) data[,"Age"]
  • (C) data[["Age"]]
  • (D) data.column("Age")
πŸ’¬ Discuss
βœ… Correct Answer: (B) data[,"Age"]

Q. In R, how do you add a new column named Height to a data frame named my_data?

  • (A) my_data$Height <- c(160, 170, 155)
  • (B) add_column(my_data, "Height", c(160, 170, 155))
  • (C) my_data[,"Height"] <- c(160, 170, 155)
  • (D) append_column(my_data, "Height", c(160, 170, 155))
πŸ’¬ Discuss
βœ… Correct Answer: (A) my_data$Height <- c(160, 170, 155)

Q. How do you create a character vector with the elements "apple", "orange", and "banana" in R?

  • (A) char_vec <- c("apple", "orange", "banana")
  • (B) vector("apple", "orange", "banana")
  • (C) create_char_vector("apple", "orange", "banana")
  • (D) char_vec(c("apple", "orange", "banana"))
πŸ’¬ Discuss
βœ… Correct Answer: (A) char_vec <- c("apple", "orange", "banana")

Q. What does the str() function do in R?

  • (A) Display the structure of an object
  • (B) Convert object to a string
  • (C) Compute the mean of an object
  • (D) Check the type of an object using string comparison
πŸ’¬ Discuss
βœ… Correct Answer: (A) Display the structure of an object

Q. In R, how do you create a data frame named my_df with columns Name and Age?

  • (A) my_df <- data.frame(Name = c("Alice", "Bob"), Age = c(25, 30))
  • (B) create_df(Name = c("Alice", "Bob"), Age = c(25, 30))
  • (C) df(Name = c("Alice", "Bob"), Age = c(25, 30))
  • (D) data_frame(Name = c("Alice", "Bob"), Age = c(25, 30))
πŸ’¬ Discuss
βœ… Correct Answer: (A) my_df <- data.frame(Name = c("Alice", "Bob"), Age = c(25, 30))

Q. What is the result of length(unique(c(1, 2, 3, 1, 2))) in R?

  • (A) 3
  • (B) 5
  • (C) 2
  • (D) 4
πŸ’¬ Discuss
βœ… Correct Answer: (A) 3

Q. In R, how is a factor converted to a numeric vector using the as.numeric() function?

  • (A) as.numeric(factor_vector)
  • (B) factor_vector(as.numeric)
  • (C) numeric(factor_vector)
  • (D) to.numeric(factor_vector)
πŸ’¬ Discuss
βœ… Correct Answer: (C) numeric(factor_vector)

Q. Which data structure in R is used to store an ordered collection of elements?

  • (A) List
  • (B) Matrix
  • (C) Data Frame
  • (D) Vector
πŸ’¬ Discuss
βœ… Correct Answer: (D) Vector

Q. What does the matrix() function create in R?

  • (A) A list of elements
  • (B) A one-dimensional array
  • (C) A two-dimensional array
  • (D) A data frame
πŸ’¬ Discuss
βœ… Correct Answer: (C) A two-dimensional array