In this article
Types and data structures
These are conceptual questions. For the routine of writing code live, read the coding interview guide.
What are the basic data types in R?
R has six basic, or atomic, vector types: logical, integer, double (the manual says "real"), complex, character and raw (R Language Definition, October 2026). A plain number such as 3 is a double and 3L is an integer. An atomic vector is a vector whose elements all share one type. Check a type with typeof().
Why it is asked: it shows whether you know what a "number" is in R. Read the full explanation: R Language Definition.
How does indexing a vector work in R?
Vectors are contiguous cells holding data, and cells are reached through indexing operations such as x[5] (R Language Definition, October 2026). R counts from one, so x[1] is the first element, not the second. A negative index drops an element, and a logical vector selects the positions that are TRUE.
Why it is asked: candidates arriving from other languages often assume counting from zero. Read the full explanation: R Language Definition.
What is the difference between a vector and a list?
Both are vectors, but they differ in element types: in an atomic vector all elements must have the same type, while in a list they can differ (Advanced R, chapter 3, October 2026). The manual calls lists "generic vectors", and list elements can themselves be lists. So "a list is not a vector" is wrong; the closely related object that is not a vector is NULL, and functions and environments are not vectors either.
Why it is asked: it tests whether your mental model of R's structures is accurate. Read the full explanation: Advanced R, Vectors.
What is NULL in R?
NULL is closely related to vectors but is not one: it has a unique type, is always length zero and cannot have any attributes (Advanced R, chapter 3, October 2026). It often serves as a generic zero-length vector. Two common uses are a missing list element, since list(a = 1)$b returns NULL, and a default argument that means "not supplied". Do not confuse it with NA, which is a value that stands for a missing observation.
Why it is asked: NULL and NA are confused often, and the difference shows care. Read the full explanation: Advanced R, Vectors.
What is a data frame?
A data frame is a named list of vectors with attributes for column names, row names and its class, "data.frame" (Advanced R, chapter 3, October 2026). Each column is a vector, so each column has one type, while the columns can differ from each other. Because it is a list underneath, list tools such as lapply work on its columns.
Why it is asked: nearly all analysis work in R starts from a data frame. Read the full explanation: Advanced R, Vectors.
Why does df$x return a column whose name only starts with x?
The $ operator matches names partially: when you extract a single column with df$x and no column x exists, a data frame selects the variable whose name starts with x (if exactly one does; if two do, you get NULL) (Advanced R, chapter 3, October 2026). This can silently return the wrong column. Use df[["x"]], which matches the whole name by default, when you need an exact lookup.
Why it is asked: it is a small trap that separates careful from careless code. Read the full explanation: Advanced R, Vectors.
What is a factor in R?
A factor is R's type for categorical data: an integer vector with a levels attribute that maps each code to a label (R Language Definition, October 2026; Advanced R, chapter 3, October 2026). Printing shows labels, but the stored values are codes, so as.numeric(f) returns codes; for numbers stored as labels, as.numeric(levels(f))[f] recovers them (R help, factor, October 2026). Check stringsAsFactors when reading data: it decides whether text columns become factors.
Why it is asked: the code-versus-label trap silently corrupts numbers. Read the full explanation: R help, factor.
Missing values
How do you test for a missing value in R?
Use is.na(x), not x == NA. The constant Not Available (NA) is a logical value of length one that holds a missing value indicator, and a calculation using it normally gives NA, so x == NA returns NA for every element (R help, NA, October 2026). For example, is.na(c(1, NA)) gives FALSE TRUE. The function anyNA does the same as any(is.na(x)), possibly faster.
Why it is asked: the wrong test is a very common bug. Read the full explanation: R help, NA.
What is the difference between NA and NaN?
Not Available (NA) is the general missing value, and NaN is a second kind of missing double value, "Not a Number", produced by undefined arithmetic such as 0/0 or Inf - Inf. The function is.na returns TRUE for both NA and NaN, while is.nan returns TRUE only for NaN (R help, is.finite, October 2026). So every NaN counts as missing, but not the reverse. A NULL, unlike both, is always length zero.
Text description of the diagram
- NaN is a second kind of missing double value.
- NULL is always length zero.
Why it is asked: it checks that you know where missing values come from. Read the full explanation: R help, is.finite and is.nan.
Is the string "NA" a missing value in R?
No. The missing value of character type, NA_character_, is distinct from the string "NA" (R help, NA, October 2026). Each vector type has its own missing constant, and plain NA is logical and is coerced to the type of the vector it joins. By default the table-reading functions treat the text NA in a file as missing (na.strings = "NA"), so a real value spelled NA, such as Namibia's country code, is lost unless you set na.strings (R help, read.table, October 2026).
Why it is asked: it appears in data-cleaning questions. Read the full explanation: R help, NA.
What does FALSE & NA return in R?
It returns FALSE, and TRUE | NA returns TRUE. Logical computations treat NA as an unknown TRUE or FALSE, so they can return a definite answer when the result does not depend on the unknown operand (R help, NA, October 2026). By the same rule, TRUE & NA stays NA, because the answer depends on the missing value.
Why it is asked: it tests reasoning about three-valued logic, not memorised output. Read the full explanation: R help, NA.
Knowing it is half the job. Saying it is the other half.
Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.
Start Free Trial →Numbers and equality
Why does sqrt(2) * sqrt(2) == 2 return FALSE, and is it a bug?
It is not a bug. The only numbers R's numeric type can represent exactly are integers and fractions whose denominator is a power of 2; all other numbers are rounded to about 53 binary digits (R frequently asked questions, October 2026). For a <- sqrt(2), a * a - 2 gives 4.440892e-16, and .3 + .6 - .9 gives -1.110223e-16, so == returns FALSE in both cases.1
Why it is asked: it separates people who understand floating point from people who blame the language. Read the full explanation: R frequently asked questions.
How do you compare two numbers safely in R?
Use all.equal(), which compares two objects with a numeric tolerance of the square root of the machine epsilon (R frequently asked questions, October 2026), about 1.490116e-08.1 When the objects differ, all.equal returns a description of the difference rather than FALSE (R help, all.equal, October 2026), so inside an if wrap it as isTRUE(all.equal(a, b)).
Why it is asked: it shows you know the safe pattern, not only the problem. Read the full explanation: R frequently asked questions.
Memory and functions
What is copy-on-modify in R?
Copy-on-modify is the behaviour that R copies an object only when you change it, so R objects behave as unchangeable, or immutable, with exceptions: an object with a single name may be modified in place, and environments are never copied (Advanced R, copy-on-modify, October 2026). After x <- c(1, 2, 3) and y <- x, both names point at one object. Changing y[[3]] creates a new object for y, and x still prints 1 2 3. The book says understanding this improves your intuition about performance.
Why it is asked: it explains why assignment is cheap and why some loops are slow. Read the full explanation: Advanced R, copy-on-modify.
What is the difference between lapply, sapply and vapply?
The function lapply returns a list the same length as X, one result per element. The function sapply is a user-friendly wrapper that by default returns a vector, a matrix or an array if appropriate; vapply adds a FUN.VALUE argument (R help, lapply, October 2026). Prefer vapply in scripts: it checks each result against the template.
For a list lst holding 1, 1:3 and 10:100, sapply(lst, length) gives 1, 3 and 91, and vapply(lst, sum, numeric(1)) gives 1, 6 and 5005.1
Why it is asked: it probes whether you write predictable code. Read the full explanation: R help, lapply.
How do you get the row and column sums of a matrix in R?
Use apply(m, 1, sum) for rows and apply(m, 2, sum) for columns: the MARGIN argument says which dimension to work along, 1 for rows and 2 for columns (R help, apply, October 2026). The base functions rowSums and colSums do the same job more directly (R help, colSums, October 2026). A matrix fills column by column unless byrow = TRUE (R help, matrix, October 2026), so for m <- matrix(1:9, nrow = 3) the row sums are 12, 15 and 18 and the column sums are 6, 15 and 24.1
Why it is asked: it checks that you know matrices fill by column, and that the apply idea extends past lists. Read the full explanation: R help, apply.
What does vectorised mean in R, and why avoid growing a vector in a loop?
A vectorised operation works on a whole vector at once, so x * 2 doubles every element without a loop (Advanced R, chapter 3, October 2026). Growing a vector inside a loop, such as x <- c(x, i), is slow for long vectors because c() returns a new vector and each pass copies the old contents, the copy-on-modify idea above. Preallocate with numeric(n) and fill it, or use vapply.
Why it is asked: it separates R code that scales from code that only works on small data. Read the full explanation: Advanced R, copy-on-modify.
What is lazy evaluation in R?
Lazy evaluation is a rule that a function argument is not evaluated until the function actually uses it. The language definition lists the "promise" as the object used to implement lazy evaluation, alongside the closure, which is a function (R Language Definition, October 2026). So an argument that is never used is never computed, and an error inside it never appears.
Why it is asked: it explains default arguments that refer to other arguments, and surprising error timing. Read the full explanation: R Language Definition.
Follow-up questions
What are the common R language interview questions?
The eighteen above cover what a screening usually probes: vector types, lists, data frames and factors, missing values, equality of numbers, copy-on-modify and the apply family. Which of them an interviewer chooses depends on the role, so treat this list as a map of the language rather than a forecast. For the general method of a coding round, read the coding interview guide.
How should I practise R interview questions?
Run each snippet and predict the output before you press enter. Questions about NA, equality and copy-on-modify are best learnt by changing one thing and watching the result. For another language's quirks, compare the JavaScript interview questions or the Java interview questions.
Is R case sensitive?
Yes, names are case sensitive (R Language Definition, October 2026). x and X are different names, and TRUE is a reserved word while true is not. This is why the capitalisation of NA and NaN matters in answers.
Where do I look up an R function while preparing?
Type ?lapply, or the name of any function, to open its help page, and read the Details and Examples sections. The manuals are on the Comprehensive R Archive Network (CRAN). If the role includes testing code, see the pytest interview questions and the quality assurance (QA) interview questions.
- R has six atomic vector types; a list is a vector too, and
NULLis a closely related object that is not. - Test for missing values with
is.na(), never== NA;NaNcounts asNA, but not the reverse. - Never test floating-point numbers with
==; useisTRUE(all.equal(a, b)). - Assignment copies only on modification, and
vapplyis the predictable member of the apply family.
Sources
- The R Language Definition — R Core Team, Comprehensive R Archive Network, 19 Oct 2026
- R help: lapply, sapply, vapply — R Core Team, 26 Oct 2026
- R help: NA, Not Available / Missing Values — R Core Team, 26 Oct 2026
- R help: is.finite, is.infinite, is.nan — R Core Team, 26 Oct 2026
- R help: read.table — R Core Team, 26 Oct 2026
- R help: apply — R Core Team, 26 Oct 2026
- R help: colSums, rowSums — R Core Team, 26 Oct 2026
- R help: matrix — R Core Team, 26 Oct 2026
- R help: factor — R Core Team, 26 Oct 2026
- R help: all.equal — R Core Team, 26 Oct 2026
- R frequently asked questions: why doesn't R think these numbers are equal? — R Core Team, 26 Oct 2026
- Advanced R, 2nd edition, chapter 3: Vectors — Hadley Wickham (Chapman and Hall/CRC), 26 Oct 2026
- Advanced R, 2nd edition, chapter 2: Names and values (copy-on-modify) — Hadley Wickham (Chapman and Hall/CRC), 26 Oct 2026