पाठ 25 / 25

Revision and Interview Questions

Recall R concepts quickly for exams and interviews.

Cheat sheet

Basics: <- assignment; atomic types double, integer (3L), character, logical; NA propagates (use is.na, na.rm = TRUE); NULL; coercion to the most flexible type. Vectors: vectorised operations, recycling, 1-based indexing, negative indices exclude, logical indexing, %in%, ifelse. Structures: lists ([[ ]] and $ extract, [ ] sub-list), factors with levels, matrices, data frames and tibbles. Programming: if needs one logical, seq_along, pre-allocate, functions with defaults and ..., lazy evaluation, \(x) lambdas, native pipe |>; lapply, vapply, purrr map_*, possibly. Tidyverse: readr, readxl, janitor; dplyr filter, select, mutate, arrange, summarise, group_by or .by, across, case_when; tidy data, pivot_longer/pivot_wider, joins including anti_join. Visualisation: ggplot2 data + aes() + geoms, facets, scales, labs, themes; EDA. Statistics: mean vs median for skew, d/p/q/r distribution functions, set.seed, bootstrap; t.test, prop.test, chisq.test, p-values vs effect sizes, p.adjust; lm, glm(family = binomial), broom. Other: stringr, lubridate (dmy, %m+%, time zones), S3 dispatch, R6, data.table, arrow, duckdb, Quarto, Shiny, renv, testthat, usethis/devtools.

Common interview questions

Answer each with a short code example.

1. What is vectorisation in R, and why does it matter?
2. How do NA and NULL differ? How do you handle missing values in summaries?
3. Explain recycling and a bug it can cause.
4. List vs vector vs data frame vs tibble: when do you use each?
5. What do [ ] and [[ ]] return for a list?
6. Explain the main dplyr verbs and group_by.
7. What is tidy data? When would you use pivot_longer?
8. Explain the grammar of graphics in ggplot2.
9. What does a p-value mean, and what does it not mean?
10. How do you interpret coefficients in linear and logistic regression?
11. How does S3 method dispatch work?
12. How would you make an R analysis reproducible?

Show the pipeline

In data interviews, writing a short dplyr pipeline that answers a business question, and explaining each step, demonstrates practical skill better than reciting function names.

त्वरित जाँच: Which dplyr verb adds or modifies columns?

  • filter
  • arrange
  • summarise
  • mutate
Answer

mutate — mutate creates or changes columns; filter keeps rows; summarise reduces groups.