R Online Quiz

Welcome to our R Online Quiz, tailored to challenge and bolster your understanding of R, a powerful language for statistical computing and graphics. This quiz spans a variety of topics, from basic syntax and data manipulation to advanced statistical techniques and graphics creation. Whether you're a statistician, data analyst, or a researcher, these questions will test your proficiency in R and provide insights into areas of improvement.

1. What is the primary use of the R language?

a) Web development
b) Mobile app development
c) Statistical analysis and data visualization
d) System administration

2. How do you install a package in R?

a) install.packages("ggplot2")
b) library(ggplot2)
c) require(ggplot2)
d) get("ggplot2")

3. What does the following R code output?

x <- c(1, 2, 3, 4, 5)
a) 3
b) 15
c) 3.0
d) Error

4. How do you create a vector in R?

a) vector <- 1:5
b) vector <- c(1, 2, 3, 4, 5)
c) vector <- list(1, 2, 3, 4, 5)
d) vector <- array(1, 2, 3, 4, 5)

5. What is the output of the following R code?

v <- c(TRUE, FALSE, T, F)
a) 4
b) 1
c) 2
d) None of the above

6. Which function in R is used to read CSV files?

a) read.csv()
b) read_csv()
c) load.csv()
d) get.csv()

7. What will the following R code output?

x <- c("apple", "banana", "cherry")
a) "banana"
b) "apple"
c) "cherry"

8. How do you check for missing values in an R vector?

vec <- c(1, 2, NA, 4, 5)
a) is.na(vec)
b) is.null(vec)
c) na.omit(vec)
d) is.missing(vec)

9. What is the function to produce a simple plot in R?

x <- 1:10
y <- x^2
plot(x, y)
a) plot(x, y)
b) graph(x, y)
c) draw(x, y)
d) sketch(x, y)

10. How do you subset a data frame in R based on a condition?

df <- data.frame(age = c(21, 22, 23), name = c("John", "Doe", "Jane"))
subset(df, age > 21)
a) subset(df, age > 21)
b) df[df$age > 21, ]
c) df[which(df$age > 21), ]
d) All of the above

11. What function is used to combine multiple data frames by rows?

a) merge()
b) cbind()
c) rbind()
d) bind()

12. What is the purpose of the lapply() function in R?

a) It applies a function to each element of a list and returns a list
b) It performs loop operations faster
c) It combines lists into a data frame
d) It applies a function iteratively to reduce elements to a single value

13. How do you generate a sequence from 1 to 10 in R?

seq <- 1:10
a) sequence(1, 10)
b) 1:10
c) seq(1, 10)
d) generate(1, 10)

14. What is the use of the %in% operator in R?

values <- c(1, 3, 5)
test <- c(1, 2, 3)
result <- test %in% values
a) It checks if elements of one vector are present in another vector
b) It performs modulo division
c) It concatenates strings
d) It multiplies two vectors

15. What function is used to randomly shuffle elements of a vector in R?

a) shuffle()
b) randomize()
c) sample()
d) mix()

16. How do you apply a custom function to each column of a data frame in R?

a) apply(df, 2, FUN)
b) lapply(df, FUN)
c) sapply(df, FUN)
d) Both a) and c) are correct

17. What does the na.omit() function do in R?

a) Fills in NA values with zeros
b) Removes rows from a data frame where any NA values are present
c) Replaces NA values with the mean of the column
d) Identifies NA values in a vector

18. How do you calculate the median of a numeric vector in R?

numbers <- c(1, 3, 5, 7, 9)
a) median(numbers)
b) mean(numbers)
c) average(numbers)
d) middle(numbers)

19. What is R's default action when it encounters an NA value in a mathematical operation?

a) It returns NA
b) It removes the NA value
c) It throws an error
d) It treats NA as zero

20. What function is used to sort a vector in R?

a) sort()
b) order()
c) rank()
d) arrange()