LAISHA
Open Laisha

ICAR-IASRI MSc and PhD Programming for Statistics & Data (R and Python): practice questions

ICAR-IASRI MSc and PhD (Agricultural Statistics, Computer Application, Bioinformatics) · India · ICAR-Indian Agricultural Statistics Research Institute with the IARI Graduate School

Original practice questions written to the published syllabus · not past papers
10worked here, free
31written to this exam in this subject
8syllabus units

What this subject covers

Writing correct, readable programs for data work: R and Python as the working languages, with the control structures, functions, data frames, vectorisation and debugging habits that later computing subjects assume. C and SAS are covered where agricultural universities still teach them.

In the exams: GATE DA 'Programming, Data Structures and Algorithms' (heavy: Python named); AICE-JRF Computer Application Unit 2 programming (heavy); AIEEA-PG Group 07 computer programming (present)

Where the 31 questions fall

How our questions for ICAR-IASRI MSc and PhD spread across the units of Programming for Statistics & Data (R and Python). Difficulty: 13 easy, 18 medium, 0 hard.

R: vectors, data frames, factors and lists7
R: functions, control flow and vectorisation6
Graphics in R (base and ggplot2) and Python (matplotlib)4
Writing functions and simple packages4
Algorithms, flowcharts and pseudocode3
Reading, cleaning and reshaping data3
Debugging, testing and code style3
Python: core types, NumPy arrays and pandas data frames1

10 practice questions, worked

Choose an answer, then open the working. Each explanation says why the right answer is right and why the others are not.

1 · R: vectors, data frames, factors and lists · medium

For a list lst in R, lst[1] and lst[[1]] return respectively:

  1. The element itself, and then a list containing it
  2. The same object in both cases
  3. A list of length one, and the element itself
  4. An error, and the element
Answer and working

C. A list of length one, and the element itself

Single brackets subset the list; double brackets extract the element.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

2 · R: functions, control flow and vectorisation · medium

Why is seq_along(x) preferred to 1:length(x) in R loops?

  1. seq_along(x) is always much faster in every case
  2. 1:length(x) is not valid syntax
  3. seq_along(x) skips missing values
  4. 1:length(x) gives c(1, 0) when x is empty
Answer and working

D. 1:length(x) gives c(1, 0) when x is empty

With an empty x, 1:0 runs the loop twice with invalid indices; seq_along gives an empty sequence.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

3 · R: functions, control flow and vectorisation · medium

R's lexical scoping means that a function looks up a free variable:

  1. In the environment where it is called
  2. Only among its arguments
  3. Where the function was defined
  4. Only in the global environment
Answer and working

C. Where the function was defined

Lookup follows the defining environment, then its parents.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

4 · Reading, cleaning and reshaping data · medium

Which join keeps only rows whose keys appear in both tables?

  1. Left join
  2. Full join
  3. Right join
  4. Inner join
Answer and working

D. Inner join

Left and right joins keep all rows of one table; full keeps all of both.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

5 · Graphics in R (base and ggplot2) and Python (matplotlib) · easy

Which ggplot2 function splits a plot into panels by a variable?

  1. facet_wrap
  2. geom_smooth
  3. scale_colour
  4. coord_flip
Answer and working

A. facet_wrap

Facets create small multiples.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

6 · Graphics in R (base and ggplot2) and Python (matplotlib) · medium

The grammar of graphics that ggplot2 implements was set out by:

  1. Tukey
  2. Fisher
  3. Knuth
  4. Wilkinson
Answer and working

D. Wilkinson

Leland Wilkinson's The Grammar of Graphics.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

7 · Graphics in R (base and ggplot2) and Python (matplotlib) · medium

A scatter-plot matrix of several variables in base R is drawn with:

  1. histogram()
  2. barplot()
  3. boxplot()
  4. pairs()
Answer and working

D. pairs()

pairs plots every pair of variables.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

8 · Writing functions and simple packages · medium

Declaring package dependencies and versions for a project mainly prevents:

  1. Viruses and malware on the shared computer
  2. Data entry errors
  3. Breakage when shared libraries change
  4. Slow plotting
Answer and working

C. Breakage when shared libraries change

Pinned versions and project environments keep analyses reproducible.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

9 · Writing functions and simple packages · easy

A well-designed function should:

  1. Print every intermediate value
  2. Use as many global variables as possible
  3. Be as long as possible
  4. Return values, not change globals
Answer and working

D. Return values, not change globals

Pure, focused functions are easier to test and reuse.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

10 · Debugging, testing and code style · medium

Which is a testing framework for R?

  1. ggplot2
  2. testthat
  3. tidyr
  4. Rcpp
Answer and working

B. testthat

pytest is the common Python framework.

Further reading: Wickham and Grolemund, R for Data Science; McKinney, Python for Data Analysis (2022); Kernighan and Ritchie, The C Programming Language (1988); Delwiche and Slaughter, The Little SAS Book (2019)

Ten here, 31 in the app. The Laisha app has every practice question we have written to ICAR-IASRI MSc and PhD in this subject, marked as you go, with timed papers, a jump-to-unanswered list and a certificate when you pass at 70 per cent.

Free for ten days, then one subscription of US$10 a month. We would rather say so here than have you find it later.

Practise the full set in Laisha →

Read the subject

Programming for Statistics & Data (R and Python)The full study manual, free ICAR-IASRI MSc and PhDFormat, sections and how it has changed

More ICAR-IASRI MSc and PhD practice

Causal Inference, Panel Data & Efficiency AnalysisStatistical & Machine Learning for AgricultureSpatial Statistics, Geostatistics & Remote Sensing for AgricultureActuarial Statistics & Crop Insurance DesignAgriculture for StatisticiansTime Series AnalysisCrop Forecasting, Weather-Based Models & Non-linear Growth ModelsDifferential Equations, Finite Differences & Numerical AnalysisData Analysis with Statistical Software & Reproducible ResearchStatistical Consulting, Research Methodology & Scientific CommunicationComputer Science Fundamentals: Architecture, Data Structures, Networks & Operating SystemsDatabases, Big Data & Agricultural Information SystemsStatistical Computing: Simulation, Resampling & AlgorithmsStatistical Ecology, Environmental & Fisheries StatisticsStatistical Genomics: QTL Mapping, GWAS & Genomic SelectionBioinformatics & Computational Biology

Programming for Statistics & Data (R and Python) for other exams

Royal Statistical Society professional awards · United Kingdom

Ask Laisha about this

Opens Laisha's chat with your question ready to send. Sign in or start free.