Questions about R: Important Frequently Asked

This post is about some frequently asked Questions about R Language. The frequently asked questions are about compilers in R, R packages, just in just-in-time compilers, procedural programming in R, and the Recycling rule of vectors. These questions will help you prepare for examinations and interviews.

Frequently Asked Questions About R

Questions about R Language

Question: What is a Compiler in R Language?
Answer: A compiler is software that transforms computer code (source code) to another computer language (target language, i.e., object code).

Question: What is a package in R Language?
Answer: The R package is a collection of R functions, compiled code, sample data, and help documentation. The R packages are stored in a directory called “library” in the R environment. The R language also installed a set of packages during installation.

Question: What is JIT?
Answer:
JIT standards for “Just in Time” compiler. It is a method to improve the run-time performance of a computer program.

Question: What is procedural Programming in R Language?
Answer:
Procedural programming is derived from structured programming and it is based on the concept of procedure call. Procedures are also known as routines, subroutines, or functions. It contains a series of computational steps to be carried out. Any procedure may be called (at any point) during a program’s execution.

Mathematical Operation in R

Question: What is the recycling of elements in a vector?
Answer: When a mathematical operation (such as addition, subtraction, multiplication, division, etc) is performed on two vectors of different lengths (the number of elements in both vectors is different), the element having a shorter length is reused to complete the mathematical operations.

vect1 <- c(4, 1, 4, 5, 6, 9)
vect2 <- c(2, 5)
vect1 * vect2 

###
8, 5, 8, 25, 12, 45

The elements of vect2 are recycled to complete the operation of all elements of vect1.

Question: What is the difference between a data frame and a matrix in R Language?
Answer: In R, the data frame contains heterogeneous data (different columns of the data frame may have different types of variable) while a matrix contains homogeneous data (all the columns of the matrix have the same type of variable). In a matrix, similar data types can be stored while in a data frame, different types of data can be stored.

See Questions about R language Missing Values

MCQs General Knowledge, MCQs in Statistics

R Quick Reference I

The article is about R Quick Reference related to Data representation in R Language, Data Types in R, Checking/Testing of special values in R, Changing the basic data types, use of Mathem operations, rounding of the numbers and outputs, and mathematical functions.

R Quick Reference

R Language A Quick Reference

R language: A Quick Reference is about learning R Programming with a short description of the widely used commands. It will help the learner and intermediate user of the R Programming Language to get help with different functions quickly. This R Quick Reference is classified into different groups. Let us start with R Language: A Quick Reference – I.

Basic Data Representation in R

In R, data may be represented as logical values, in scientific notation, as a complex, or as a float number. The are certain values such as NA, NULL, NaN, and Inf values.

R CommandShort Description
True, FalseLogical true or false
1.23e10A number in scientific notation $1.23\times 10^{20}$
3.4iA complex number
“Hello”A String/ Characters
NAMissing Value representation (in any type of vector)
NULLMissing Value indicator in lists
NaNNot a number
-InfNegative Infinity
InfPositive infinity

Checking/ Testing the Basic Data Types in R

The type of data can be checked using some functions such as is.logical(), is.numeric(), is.list(), is.character(), is.vector() or is.complex() function.

R CommandShort Description
is.logical(x)Results in true for logical vectors
is.numeric(x)Results in true for numeric vectors
is.character(x)Results in true for character vectors
is.list(x)Results in true for lists
is.vector(x)Results in true for both lists and vectors
is.complex(x)Results in true for complex vectors

Checking/ Testing the Special Values

The type of special values can be checked using is.na(), is.nan(), is.finite(), is.ordered(), and is.factor() etc., functions

R CommandShort Description
is.na(x)Results in true for elements that are NA or NaN
is.nan(x)Results in true for elements that are NaN
is.null(x)Results in true whether $x$ is NULL
is.finite(x)Results in true for finite elements (e.g., not NA, NaN, Inf or -Inf)
is.infinite(x)Results in true for elements equal to Inf or -Inf
is.factor(x)Results in true for a factors and ordered factors
is.ordered(x)Results in true for ordered factors

Changing Basic Data Types in R

The Data Types in R can be changed by using functions such as, as.logical(), as.numeric(), as.list(), or as.numeric() etc., functions.

Type CoercionShort Description
as.logical(x)Coerces to a vector (However, lists remain lists)
as.numeric(x)Coerces a vector to a numeric vector
as.character(x)Coerces a vector to a character vector
as.list(x)Coerces a vector to a list
as.vector(x)Coerces to a vector (However, lists remains lists)
unlist(x)Converts a list to a vector
as.complex(x)Coerces to a vector (However, lists remain lists)

Basic Mathematical Operations

R can be used as a calculator. Mathematical operations such as addition, subtraction, multiplication, and division can also be performed.

Basic Math OperationShort Description
x + yPerform addition between the $x$ and $y$ vector
x – yPerform subtraction between the $x$ and $y$ vector
x * yPerform multiplication between the $x$ and $y$ vector
x / yPerform division between the $x$ and $y$ vector
x ^ yPerform exponentiation, “$x$ raised to power $y$”
x %% yComputes remainder, “$x$ modulo $y$”
x %/% yPerforms Integer division, “$x$ divided by $y$”, discard the fractional part

Rounding off the Numbers

The numbers or values of a variable can be rounded as desired.

R CommandShort Description
round(x)Round down the values of a variable to the next lowest integer
round(x, d)Round the values of a variable $x$ to the $d$ decimal places
signif(x, d)Round the values of a variable $x$ to $d$ significant digits
floor(x)Round down the values of a variable to next lowest integer
ceiling(x)Round up the values of a variable to the highest integer

Common Mathematical Functions

The commonly used mathematical functions in the R language are abs(), sqrt(), exp(), log(), and different bases of log functions.

R CommandShort Description
abs(x)Absolute values
sqrt(x)Computes the square root of the values of a variable
exp(x)Computes $e^x$
log(x)Computes the log values of the variable $x$
log10(x)Computes the log base 10 (common log) of the variable $x$
log2(x)Computes the log base 2 of the variable $x$
log(x, base=b)Computes the log base $b$ of the variable $x$

Trigonometric and Hyperbolic Functions

Following is the list of different trigonometric and Hyperbolic functions

Trigonometric FunctionsShort Description
sin(x), cos(x), tan(x)Computes the trigonometric values, sin, cos, and tan of a vector $x$
asin(x), acos(x), atan(x)Computes the inverse trigonometric values of a vector $x$
atan2(x, y)Computes arc tangent with two arguments
sinh(x), cosh(x), tanh(x)Computes hyperbolic values of a vector $x$
asinh(x), acosh(x), atanh(x)Computes the inverse hyperbolic values of a vector $x$

Special Mathematical Functions

The following is the list of special mathematical functions.

Mathematical FunctionsShort Description
beta(x, y)The beta function
lbeta(x, y)The log beta function
gamma(x)The gamma function
lgamma(x)The log gamma function
psigamma(x, deriv = 0)The psigamma function
digamma(x)The digamma function
trigamma(x)The trigamma function

R Frequently Asked Questions

MCQs in Statistics

Practicing R for Statistical Computing (2023)

Practicing R for Statistical Computing R faqs

The book “Practicing R for Statistical Computing” is designed to provide a comprehensive introduction to R language for data presentation, manipulation, and statistical data analysis. The book covers fundamentals of data structures in R language such as vectors, matrices, arrays, and lists, along with techniques for exploratory data analysis, the transformation of the data, and its manipulation. The book explains basic statistical concepts and demonstrates their implementation including descriptive statistics, graphical representation of data, probability, popular probability distributions, and hypothesis testing. It also explores linear and non-linear modeling, model selection, and diagnostic tools available in R.

Practicing R for Statistical Computing

The book also covers flow control and conditional computation using ‘if’ conditions and loops. A useful discussion is also done about functions and resources for further learning. It provides an extensive list of functions grouped according to statistics classification, which can be helpful for both statisticians and R programmers. The use of different graphic devices, high-level and low-level graphical procedures, and adjustment of parameters are also explained. Throughout the book, R commands, functions, and objects are printed in different fonts for understanding and easy identification. The possible standard errors, warnings, and mistakes by users in the R language are also discussed and classified, and explanations on how to prevent them are given.

Chapter-wise downloadable R code files from Practicing R for Statistical Computing are:

Chapter 1: R Language: Introduction

Chapter 2: Obtaining and Installing R Language

Chapter 3: Using R as a Calculator

Chapter 4: Data Mode and Data Structure

Chapter 5: Working with Data

Chapter 6: Descriptive Statistics

Chapter 7: Probability and Probability Distributions

Chapter 8: Confidence Intervals and Comparison Tests

Chapter 9: Correlation & Regression Analysis

Chapter 10: Graphing in R

Chapter 11: Control Flow: Selection and Iteration

Chapter 12: Functions and R Resources

Chapter 13: Common Errors and Mistakes

Chapter 14: Functions for Better Programming

Chapter 15: This chapter lists the widely used built-in functions (No R code exists)

Chapter 16: This chapter lists several important R packages (No R code exists)

Authors:

Muhammad Aslam is Professor in the Department of Statistics at Bahauddin Zakariya University,

Muhammad Imdad Ullah is an Assistant Professor in the Department of Statistics at Ghazi University,

Muhammad Aslam is a Professor at the Department of Statistics at Bahauddin Zakariya University, Multan, Pakistan. He holds a Ph.D. in Statistics, a Master’s degree in Statistics, and a Post-Graduate Diploma in Computer Programming and Computing Statistics from the same university. He also completed his Post-Doctorate from the Institut de Mathematiques de Bourgogne, Dijon, France.

Professor Aslam’s research is mainly focused on regression analysis and statistical inference, with a particular interest in simulation studies using computer programming. With more than 25 years of teaching experience, he has published more than 120 research articles in several prestigious international journals. Nine research scholars have completed their Ph.D. degrees under his guidance. Muhammad Imdad Ullah, the co-author of this book, is among these scholars. 

Muhammad Imdad Ullah is an Assistant Professor at the Department of Statistics, Ghazi University, Dera Ghazi Khan, Pakistan. He received his Ph.D. degree from Bahauddin Zakariya University. He has also earned a Post-Graduate Diploma in Computer Programming and Computing Statistics. His Ph.D. work is about the development of R packages addressing linear regression models with the issue of multicollinearity. This work led to the development of three R packages—mctest, lmridge, and liureg —and three research articles based on these packages were published in The R Journal. His area of expertise includes computer programming and statistical computations. With over 14 years of teaching experience, he has authored 11 research publications.

Practicing R Language for Statistical Copmuting

Learn Statistics and Data Analysis