R Programming Aptitude Test

This post presents an R Programming Aptitude Test with 25 multiple-choice questions for beginners. These beginner-level MCQ questions cover essential aspects of R programming and are designed to test fundamental understanding and basic syntax.

1. What is the correct way to assign a value to a variable in R?

a) variable <- 10
b) variable = 10
c) variable == 10
d) a) and b) are correct

2. Which function in R is used to read data from a CSV file?

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

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

a) Converts data to string type
b) Sorts data
c) Displays the structure of an R object
d) Concatenates strings

4. How do you create a vector in R?

a) vector = c(1, 2, 3)
b) vector = (1, 2, 3)
c) vector = [1, 2, 3]
d) vector = {1, 2, 3}

5. Which function is used to install packages in R?

a) install.packages()
b) library()
c) require()
d) load.package()

6. What is the output of the expression sqrt(16) in R?

a) 16
b) 4
c) 8
d) 256

7. How do you check the type of a variable in R?

a) typeof()
b) type()
c) getType()
d) varType()

8. What is R primarily used for?

a) Web development
b) Statistical computing and graphics
c) System programming
d) Mobile applications

9. How do you comment on a line of code in R?

a) #
b) //
c) <!– –>
d) **

10. What is the purpose of the NA value in R?

a) It represents a syntax error
b) It denotes a missing or undefined value
c) It indicates a negative value
d) It is used for debugging

11. Which of these is not a valid data frame operation in R?

a) Adding a new column
b) Merging two data frames
c) Looping through rows
d) Creating a data frame from a list

12. How do you access elements in a list?

a) Using the dot notation
b) Using the double bracket notation [[ ]]
c) Using curly braces { }
d) Using parentheses ( )

13. What does the summary() function in R provide?

a) A list of errors in the code
b) A concise statistical summary of the data
c) A detailed summary including null values
d) A summary of functions used in the script

14. How do you generate a sequence of numbers from 1 to 10 in R?

a) range(1, 10)
b) seq(1, 10)
c) sequence(1, 10)
d) list(1:10)

15. Which operator is used for matrix multiplication in R?

a) *
b) x
c) %*%
d) **

16. How do you create a factor in R?

a) factor()
b) createFactor()
c) as.factor()
d) a) and c) are correct

17. What is the default method to handle categorical data in R?

a) Characters
b) Integers
c) Factors
d) Strings

18. What does the function rm() do?

a) Removes variables from the memory
b) Deletes files from the disk
c) Removes missing values from data
d) Resets the R environment

19. How do you subset data in R?

a) Using the subset() function
b) Using the filter() function
c) Using SQL queries
d) Using the cut() function

20. Which function would you use to calculate the mean of a numeric vector?

a) mean()
b) average()
c) sum()
d) total()

21. What does the apply() function do?

a) Applies a function to margins of an array or matrix
b) Changes the data type of an array
c) Applies a CSS style to a plot
d) None of the above

22. How do you save a plot as a PDF in R?

a) save.plot(“plot.pdf”)
b) pdf(“plot.pdf”); plot(x, y); dev.off()
c) plot.save(“plot.pdf”)
d) export.plot(“plot.pdf”)

23. What is the purpose of the table() function in R?

a) To format data as a table
b) To create contingency tables from data
c) To visualize data in a tabular format
d) To import data from SQL tables

24. How is a dataset imported from an Excel file in R?

a) read.csv(“file.xlsx”)
b) read.xls(“file.xlsx”)
c) read.xlsx(“file.xlsx”)
d) read.excel(“file.xlsx”)

25. What is the use of the lapply() function in R?

a) Applies a function to lists and returns a list
b) Linearly interpolates values
c) Applies a looping construct over a list
d) None of the above

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top