R Language Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is R?
R is a programming language and free software environment for statistical computing and graphics.
Example:
print('Hello, R!')
Ques 2. How do you assign a value to a variable in R?
You can use the assignment operator <- or =.
Example:
x <- 10
Ques 3. Explain what a data frame is in R.
A data frame is a two-dimensional, heterogeneous tabular data structure with rows and columns.
Example:
df <- data.frame(Name=c('John', 'Jane'), Age=c(25, 30))
Ques 4. What is the use of the 'attach()' function in R?
The attach() function is used to attach a data frame to the search path, making it easier to refer to variables in the data frame.
Example:
attach(df)
Ques 5. How can you install a package in R?
You can use the install.packages() function.
Example:
install.packages('packageName')
Ques 6. What is the purpose of the 'str()' function in R?
The 'str()' function is used to display the structure of an R object. It provides a compact way to see the internal structure of data objects in R.
Example:
str(my_data)
Ques 7. How can you check if a variable is defined in R?
You can use the 'exists()' function to check if a variable exists in the specified environment.
Example:
exists('my_variable')
Ques 8. Explain the purpose of the 'ggplot2' package in R.
'ggplot2' is a popular data visualization package in R that allows users to create complex and customized plots with a grammar of graphics approach.
Example:
library(ggplot2)
ggplot(data = my_data, aes(x = variable1, y = variable2)) + geom_point()
Ques 9. What is the difference between 'ls()' and 'objects()' functions in R?
'ls()' and 'objects()' both list objects in the current environment, but 'ls()' is a shorthand form of 'objects()' and has additional options.
Example:
ls()
# or
objects()
Ques 10. How can you read data from a CSV file in R?
You can use the 'read.csv()' function to read data from a CSV file in R.
Example:
my_data <- read.csv('file.csv')
Ques 11. What is the purpose of the 'setwd()' function in R?
The 'setwd()' function is used to set the working directory in R. It changes the current working directory to the specified path.
Example:
setwd('/path/to/directory')
Ques 12. How can you install and load a package in R using a single command?
You can use the 'install.packages()' and 'library()' functions in a single line to install and load a package.
Example:
install.packages('my_package'); library('my_package')
Ques 13. Explain the purpose of the 'summary()' function in R.
The 'summary()' function is used to obtain a summary of the central tendency, dispersion, and shape of a distribution.
Example:
summary(my_data)
Most helpful rated by users:
Related interview subjects
Embedded C interview questions and answers - Total 30 questions |
C++ interview questions and answers - Total 142 questions |
VBA interview questions and answers - Total 30 questions |
COBOL interview questions and answers - Total 50 questions |
R Language interview questions and answers - Total 30 questions |
Python Coding interview questions and answers - Total 20 questions |
Scala interview questions and answers - Total 48 questions |
Swift interview questions and answers - Total 49 questions |
Golang interview questions and answers - Total 30 questions |