Skip to content

Statistical Programmer Interview Questions & Answers

40 questions for Statistical Programmer interviews — 7 easy, 29 medium, 4 hard.

About the Statistical Programmer role

A Statistical Programmer writes validated R code to produce datasets, tables, listings and figures for clinical trials and regulated research. They follow standards such as CDISC SDTM and ADaM, document every step and work with biostatisticians on analysis plans. Pharma companies and clinical research organizations in Bengaluru, Hyderabad and Mumbai increasingly use R alongside SAS for submissions. Attention to detail and documentation discipline matter more than speed here.

Clinical data standards Tables and listings Hypothesis testing Code validation R Markdown
Solved for this roleStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
3 questions free Unlock the rest in seconds
01

Explain the different types of joins in dplyr.

Save to ▾
Show answer
left_join() keeps all rows of the left table and adds matching columns from the right, inner_join() keeps only matching rows, right_join() keeps all rows of the right table and full_join() keeps all rows from both, filling NA where there is no match. Keys are given with by = join_by(customer_id) or by = c('id' = 'cust_id') for different names. Left joins are most common when enriching a fact table with lookup details.
02

How do you split one column into several, or combine columns into one?

Save to ▾
Show answer
tidyr provides separate_wider_delim() to split and unite() to combine. library(tidyr) df <- tibble(full_name = c('Amit Kumar', 'Neha Singh'), dob = c('12-05-1999', '03-11-2000')) df %>% separate_wider_delim(full_name, delim = ' ', names = c('first', 'last')) df %>% separate_wider_delim(dob, '-', names = c('d', 'm', 'y')) %>% unite('dob_iso', y, m, d, sep = '-')
03

How do you create a column with multiple conditions in dplyr?

Save to ▾
Show answer
case_when() evaluates conditions in order and returns the value of the first one that is TRUE; .default handles the rest. customers <- customers %>% mutate(segment = case_when( spend >= 50000 ~ 'Platinum', spend >= 20000 ~ 'Gold', spend >= 5000 & visits > 5 ~ 'Silver', .default = 'Regular' )) # simple two-way split mutate(df, high_value = if_else(spend > 20000, 'Yes', 'No'))
04

Why did you choose to learn R?

Save to ▾
Show answer
I chose R because I enjoy working with data and statistics, and R is designed exactly for that. During my coursework I used it for a project analysing student performance, where dplyr and ggplot2 helped me move from raw data to clear insights quickly. I like that results are reproducible with R Markdown. I am also learning SQL and basic Python, so I can work comfortably in a mixed team and pick the right tool for each task.
05

Show different ways to index vectors and data frames in R.

Save to ▾
Show answer
R indexes from 1 and supports positive, negative, logical and name-based indexing. x <- c(a = 10, b = 20, c = 30, d = 40) x[2] # 20 x[-1] # drop first x[c('a', 'd')] # by name x[x > 15] # logical filter which(x > 15) # positions df[df$age > 30, c('name', 'city')] df[order(-df$salary), ][1:5, ] # top 5 salaries
06

What is the difference between Quarto and R Markdown?

Save to ▾
Show answer
Quarto is the next-generation publishing system from Posit. It works with R, Python, Julia and Observable, and is a standalone command-line tool rather than an R package. It uses the same knitr engine for R and similar syntax, with chunk options written as #| comments. Quarto adds consistent support for websites, books, presentations and dashboards. R Markdown is still supported, but new projects increasingly use Quarto, especially in mixed R and Python teams.
07

How do you generate the same report for each of 20 regions automatically?

Save to ▾
Show answer
Use a parameterized Quarto or R Markdown report and render it in a loop. # report.qmd header: # params: # region: 'North' # then use params$region in the code regions <- unique(sales$region) purrr::walk(regions, function(r) { quarto::quarto_render( 'report.qmd', execute_params = list(region = r), output_file = paste0('report_', r, '.html') ) })
08

Code reviews show inconsistent R code style across the team. How would you standardise it?

Save to ▾
Show answer
I would adopt the tidyverse style guide as the team standard, then automate it rather than relying on reviewers. styler reformats code automatically, including an RStudio add-in, and lintr flags issues such as long lines, unused variables and inconsistent naming. I add lintr to a pre-commit hook or a GitHub Actions check so pull requests are checked automatically. A short template for new scripts and projects helps new joiners follow the same structure.
09

How do you perform a t-test in R?

Save to ▾
Show answer
t.test() handles one-sample, two-sample and paired tests. Welch's test, which does not assume equal variances, is the default. # two independent groups t.test(score ~ batch, data = students) # paired: before vs after training t.test(after, before, paired = TRUE) # one-sample against a target of 30 minutes t.test(delivery_time, mu = 30, alternative = 'greater') res <- t.test(score ~ batch, data = students) res$p.value; res$conf.int
10

You ran an A/B test on a checkout page: 4.1 percent conversion versus 4.6 percent. How do you decide if the difference is real?

Save to ▾
Show answer
Conversion is a proportion, so I use a two-proportion test: prop.test(c(conv_a, conv_b), c(n_a, n_b)). I check the p-value and, more importantly, the confidence interval for the difference. Before trusting it, I confirm the sample size was planned in advance, the test ran for full weeks to cover weekday effects, users were randomized properly and nobody stopped the test early when results looked good. Then I judge business significance.
11

Where do you see yourself in three years in an R or analytics career?

Save to ▾
Show answer
In three years I see myself as a strong data analyst or junior data scientist who can own analyses end to end, from understanding the business question to building reproducible reports and models in R. I want to deepen my statistics and machine learning skills and learn cloud tools used by the team. I would also like to mentor new joiners, as seniors helped me, and contribute to reusable internal tools.
12

How do you write unit tests for an R function?

Save to ▾
Show answer
testthat organises tests into files under tests/testthat/ using expectations. # tests/testthat/test-gst.R test_that('gst_price adds 18 percent by default', { expect_equal(gst_price(100), 118) expect_equal(gst_price(c(100, 200)), c(118, 236)) }) test_that('gst_price rejects text input', { expect_error(gst_price('abc'), 'numeric') }) # run all tests devtools::test()
13

What is the difference between %>% and |> in R?

Save to ▾
Show answer
%>% comes from the magrittr package and |> is the native pipe built into R since version 4.1. Both pass the left side as the first argument of the right side, so df |> filter(x > 1) equals filter(df, x > 1). The native pipe is faster and needs no package, but it uses _ as a named placeholder only, while %>% supports the dot placeholder anywhere. New code increasingly uses |>, and both work with dplyr.
14

What are the main dplyr verbs?

Save to ▾
Show answer
dplyr has a small set of verbs for data transformation: filter() keeps rows that meet conditions, select() picks columns, mutate() creates or changes columns, arrange() sorts rows, summarise() reduces groups to summary rows and group_by() defines groups for the next operations. Others include distinct(), rename(), relocate(), count() and slice(). Each takes a data frame as the first argument and returns a data frame, so verbs chain naturally with the pipe.
15

Explain reactivity in Shiny.

Save to ▾
Show answer
Shiny uses reactive programming: outputs automatically update when the inputs they depend on change. Inputs are reactive sources, outputs such as renderPlot() are reactive endpoints, and reactive() expressions are cached intermediate results that recompute only when their dependencies change. For example, filtering data once in a reactive() and using it in three charts avoids filtering three times. Shiny tracks dependencies automatically, so you do not write explicit event handlers for most cases.
16

What is the difference between reactive(), observe() and observeEvent() in Shiny?

Save to ▾
Show answer
reactive() creates a cached value that other code can read, such as filtered data, and it is lazy, recomputing only when needed. observe() runs code for its side effects whenever any reactive dependency changes, returning nothing. observeEvent() runs side effects only when a specific event fires, such as a button click, ignoring other dependencies. Use reactive() for computing values and observeEvent() for actions like saving data or showing notifications.
17

What are semi_join() and anti_join() used for?

Save to ▾
Show answer
They are filtering joins: they keep rows of the left table based on matches in the right table but add no columns. semi_join() keeps rows that have a match, and anti_join() keeps rows that have no match. For example, anti_join(customers, orders, by = 'customer_id') lists customers who never ordered. They are also safer than inner joins for filtering, since they never duplicate rows when the right table has repeated keys.
18

How do you connect R to a SQL database and run queries?

Save to ▾
Show answer
DBI provides a common interface, with drivers such as RPostgres, RMariaDB or odbc. library(DBI) con <- dbConnect(RPostgres::Postgres(), host = Sys.getenv('DB_HOST'), dbname = 'sales', user = Sys.getenv('DB_USER'), password = Sys.getenv('DB_PASS')) orders <- dbGetQuery(con, 'SELECT * FROM orders WHERE order_date >= $1', params = list('2026-01-01')) dbWriteTable(con, 'daily_summary', summary_df, append = TRUE) dbDisconnect(con)
19

What is the structure of an R package?

Save to ▾
Show answer
A minimal package has a DESCRIPTION file with metadata and dependencies, a NAMESPACE file listing exported functions, an R/ folder with function code, a man/ folder for documentation and usually tests/ for testthat tests. The usethis and devtools packages create and manage this: usethis::create_package(), use_r(), use_test(), and devtools::document(), test() and check(). Documentation is written as roxygen2 comments above each function. Internal packages are ideal for sharing team utilities.
20

How do you build a logistic regression model for churn in R?

Save to ▾
Show answer
Use glm() with family = binomial; predictions with type = 'response' are probabilities. fit <- glm(churned ~ tenure + monthly_charges + contract, data = train, family = binomial) summary(fit) exp(coef(fit)) # odds ratios test$prob <- predict(fit, newdata = test, type = 'response') test$pred <- ifelse(test$prob > 0.5, 1, 0) table(actual = test$churned, predicted = test$pred)
21

Why is ungroup() important in dplyr?

Save to ▾
Show answer
A grouped data frame stays grouped after mutate() and some other verbs, so later operations silently run per group. For example, a mutate(share = sales / sum(sales)) meant to compute share of grand total would compute share within each group instead. Calling ungroup() after grouped work, or using .groups = 'drop' in summarise() or the .by argument for one-off grouping, prevents these subtle bugs in long pipelines.
22

Explain the d, p, q and r functions for probability distributions in R.

Save to ▾
Show answer
Each distribution has four functions: d for density, p for cumulative probability, q for quantiles and r for random draws. dnorm(0) # density at 0 pnorm(1.96) # P(Z <= 1.96) = 0.975 qnorm(0.975) # 1.96 rnorm(5, mean = 50, sd = 10) dbinom(3, size = 10, prob = 0.2) # exactly 3 successes ppois(2, lambda = 4) # P(X <= 2) qt(0.975, df = 20) # t critical value
23

Your dplyr pipeline is too slow on a 50 million row dataset. What are your options?

Save to ▾
Show answer
I can keep dplyr syntax but change the backend. dtplyr translates dplyr code to data.table, which is much faster in memory. duckdb with dbplyr runs the pipeline in an embedded columnar database, often handling data larger than RAM. arrow lets me query Parquet files with dplyr verbs lazily. I would also filter and select early, avoid row-wise operations and profile the pipeline to find the slow step before rewriting anything.
24

How do you check whether data is normally distributed in R?

Save to ▾
Show answer
Combine visual checks with formal tests, because tests become oversensitive with large samples. hist(x, breaks = 30) qqnorm(x); qqline(x, col = 'red') shapiro.test(x) # works for n between 3 and 5000 library(ggplot2) ggplot(df, aes(sample = x)) + stat_qq() + stat_qq_line() # for model residuals plot(lm_fit, which = 2)
25

Tell me about feedback you received in a code review and what you changed.

Save to ▾
Show answer
Situation: in my first quarter, a senior reviewed my R reporting script. Task: address the review comments. Action: the main feedback was that my 300-line script mixed data loading, cleaning and plotting with repeated code. I split it into small functions, added input checks and moved constants to a config file. Result: the next report took half the time to build, and I now structure every new script this way from the start.
26

Your data is heavily skewed and the sample is small. Can you still use a t-test?

Save to ▾
Show answer
With small, heavily skewed samples the t-test's normality assumption is doubtful. I would check with a histogram, Q-Q plot or shapiro.test(). Options are a non-parametric test, wilcox.test() for two groups or kruskal.test() for more, a log transformation if the data is right-skewed and positive, or a bootstrap confidence interval for the difference in means. With large samples, the Central Limit Theorem usually makes the t-test acceptable.
27

How do you compare means across more than two groups in R?

Save to ▾
Show answer
Use one-way ANOVA, then a post-hoc test to see which pairs differ. fit <- aov(sales ~ region, data = stores) summary(fit) # overall F-test TukeyHSD(fit) # pairwise comparisons # check assumptions plot(fit, which = 2) # Q-Q of residuals bartlett.test(sales ~ region, data = stores) # non-parametric alternative kruskal.test(sales ~ region, data = stores)
28

How do you reshape data between wide and long formats in R?

Save to ▾
Show answer
tidyr's pivot_longer() turns columns into rows and pivot_wider() does the reverse. library(tidyr) # wide: product, Jan, Feb, Mar long <- sales_wide %>% pivot_longer(cols = Jan:Mar, names_to = 'month', values_to = 'sales') wide <- long %>% pivot_wider(names_from = month, values_from = sales, values_fill = 0)
29

Tell me about a dashboard or app you built in R.

Save to ▾
Show answer
Situation: regional sales managers waited for a weekly emailed PDF and could not drill into their own data. Task: give them self-service access. Action: I built a Shiny app with filters by region, product and period, used pre-aggregated tables for speed and deployed it on the internal server with login. I ran a short demo and gathered feedback. Result: over 40 managers used it weekly, and ad hoc data requests to our team fell by about half.
30

You notice database passwords hardcoded in a shared R script. What do you do?

Save to ▾
Show answer
I remove them immediately, inform the owner and ask for the password to be rotated, since it may exist in version history. Then I store credentials outside the code, in a user-level .Renviron file read with Sys.getenv(), the keyring package backed by the operating system's credential store, or the server's secret management, such as environment variables in Posit Connect. I make sure .Renviron is listed in .gitignore and scan the repository history.
31

What is Shiny and how is a Shiny app structured?

Save to ▾
Show answer
Shiny is an R package for building interactive web applications without writing HTML or JavaScript. An app has a ui that defines layout and inputs such as dropdowns and sliders, and a server function that contains R logic and creates outputs such as plots and tables. shinyApp(ui, server) runs the app. Analytics teams use Shiny for internal dashboards, what-if calculators and tools that let business users explore data.
32

Salary data has a few extreme values that distort averages. How do you handle them?

Save to ▾
Show answer
First I investigate whether they are data errors, such as an extra zero, or genuine high earners. I flag outliers with the IQR rule, values beyond Q1 - 1.5 IQR or Q3 + 1.5 IQR, or with percentiles. Errors I fix or remove with documentation. Genuine values I keep, but I report the median alongside the mean, or winsorize at the 1st and 99th percentiles for modelling. The choice depends on the business question.
33

What is plumber in R?

Save to ▾
Show answer
plumber turns R functions into REST API endpoints using special comments. You annotate a function with #* @get /predict and its arguments become query parameters, then run the API with pr_run(). Other systems, such as a Java web app or a Python service, can call the R model over HTTP and receive JSON. It is commonly used to serve model predictions, and it can be deployed in Docker or on Posit Connect.
34

An R script must run every morning at 7 AM and email a report. How do you schedule it?

Save to ▾
Show answer
On a Linux server I schedule Rscript with cron, for example 0 7 * * * Rscript /path/report.R, and on Windows with Task Scheduler or the taskscheduleR package. Posit Connect can schedule Quarto reports and email them directly. GitHub Actions can run scheduled workflows for non-sensitive jobs. The script itself renders the report and sends it with blastula or emayili. I add logging and an alert on failure so silent misses are caught.
35

How do you add logging to a production R script?

Save to ▾
Show answer
The logger package gives levelled, timestamped logs written to the console or a file. library(logger) log_appender(appender_file('logs/etl.log')) log_threshold(INFO) log_info('ETL started') res <- tryCatch({ df <- load_orders() log_info('Loaded {nrow(df)} rows') df }, error = function(e) { log_error('Load failed: {conditionMessage(e)}') quit(status = 1) }) log_info('ETL finished')
36

What is the difference between Pearson and Spearman correlation?

Save to ▾
Show answer
Pearson correlation measures the strength of a linear relationship between two numeric variables and is sensitive to outliers. Spearman correlation is computed on ranks, so it measures monotonic relationships and is robust to outliers and non-normal data. In R, cor(x, y, method = 'spearman') and cor.test() compute them. For example, ad spend and sales with diminishing returns may show a moderate Pearson value but a high Spearman value.
37

You need month-over-month sales growth for each product. How do you calculate it in R?

Save to ▾
Show answer
I first aggregate to one row per product and month with group_by() and summarise(). Then I group by product, arrange by month and use mutate(growth = (sales - lag(sales)) / lag(sales) * 100). The first month for each product becomes NA, which is correct. I make sure months with zero sales exist using tidyr::complete(), otherwise lag() compares non-consecutive months. Finally I round and format growth for reporting.
38

Explain Type I and Type II errors.

Save to ▾
Show answer
A Type I error is rejecting a true null hypothesis, a false positive, and its probability is the significance level alpha, usually 0.05. A Type II error is failing to reject a false null hypothesis, a false negative, with probability beta; power is 1 - beta. For example, launching a feature that does not actually help is a Type I error, while dropping a feature that really works is Type II. Larger samples reduce Type II errors.
39

What is bootstrapping and when would you use it?

Save to ▾
Show answer
Bootstrapping estimates the sampling distribution of a statistic by resampling the data with replacement many times and recomputing the statistic each time. The spread of those results gives standard errors and confidence intervals without assuming normality. It is useful for medians, ratios or complex metrics like revenue per user, where formulas are hard. In R, the boot package or a simple replicate() loop with sample(x, replace = TRUE) does it.
40

How would you impute missing values differently for each group?

Save to ▾
Show answer
I group by the relevant category, such as product category, and replace NAs with that group's median: group_by(category) %>% mutate(price = coalesce(price, median(price, na.rm = TRUE))) %>% ungroup(). Group medians are more realistic than a global value. I also add a flag column marking imputed rows so models and reviewers can see them. If a whole group is missing, I fall back to the overall median, and for important features I consider model-based imputation.

Frequently asked questions

What does a Statistical Programmer do?

A Statistical Programmer writes validated R code to produce datasets, tables, listings and figures for clinical trials and regulated research. They follow standards such as CDISC SDTM and ADaM, document every step and work with biostatisticians on analysis plans. Pharma companies and clinical research organizations in Bengaluru, Hyderabad and Mumbai increasingly use R alongside SAS for submissions. Attention to detail and documentation discipline matter more than speed here.

Which skills are tested in a Statistical Programmer interview?

Expect questions on Clinical data standards, Tables and listings, Hypothesis testing, Code validation, R Markdown. Most rounds also ask you to explain a project and solve one practical problem live.

How do I prepare for a Statistical Programmer interview?

Revise Statistics and Hypothesis Testing, Data Wrangling with dplyr and tidyr, Reports, Shiny and Production R first using the topic sheets, practise the questions on this page aloud, then do one full mock interview to practise timing.