LAISHA
Open Laisha

Royal Statistical Society professional awards Programming for Statistics & Data (R and Python): practice questions

Royal Statistical Society professional awards (Data Analyst, GradStat, CStat) · United Kingdom · Royal Statistical Society

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

About Royal Statistical Society professional awards

Royal Statistical Society professional awards (Data Analyst, GradStat, CStat) is a professional certification run by Royal Statistical Society, for candidates in United Kingdom. Recognition by application against qualifications and work-based experience; CStat requires professional training and experience. Not a written exam.

Source: rss.org.uk.

Checked against the exam body's published information. Formats and fees change; confirm the current edition there before you book.

Programming for Statistics & Data (R and Python) in Royal Statistical Society professional awards

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.

Our 21 Royal Statistical Society professional awards questions in this subject: 3 easy, 16 medium, 2 hard, across 7 units.

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.

These 10 were written to Royal Statistical Society professional awards and are not shown on any other exam's page.

Question 1 · medium

In R, what does c(1, 2, 3, 4) + c(10, 20) return?

  1. 11 22 13 24
  2. 11 22 3 4
  3. 11 22
  4. An error
Answer and working

A. 11 22 13 24

The shorter vector is recycled: 10, 20, 10, 20.

Question 2 · hard

In R, 0.1 + 0.2 == 0.3 evaluates to FALSE. The correct way to compare is:

  1. isTRUE(all.equal(0.1 + 0.2, 0.3))
  2. as.integer(0.1 + 0.2) == 0.3
  3. round(0.1 + 0.2) == 0.3
  4. 0.1 + 0.2 = 0.3
Answer and working

A. isTRUE(all.equal(0.1 + 0.2, 0.3))

Floating-point values are inexact; all.equal compares within a tolerance.

Question 3 · medium

Which R function computes the mean yield for each variety, given vectors yield and variety?

  1. lapply(yield, mean)
  2. apply(yield, 1, mean)
  3. mean(yield, variety)
  4. tapply(yield, variety, mean)
Answer and working

D. tapply(yield, variety, mean)

tapply applies a function within groups defined by a factor.

Question 4 · medium

A left join of a yield table (100 plots) to a treatment table by plot identifier gives 112 rows. The most likely cause is:

  1. Missing yields in some of the plots in the yield table
  2. Duplicated plot keys in the treatment table
  3. Wrong column types
  4. The join was an inner join
Answer and working

B. Duplicated plot keys in the treatment table

Duplicate keys multiply matching rows.

Question 5 · medium

Before analysing a newly read data set, which check is least informative?

  1. Counting missing values per column
  2. Checking ranges and types
  3. Printing the first value of each column only
  4. Listing distinct values of categorical variables
Answer and working

C. Printing the first value of each column only

One value reveals little; missing counts, ranges and categories find most problems.

Question 6 · medium

In ggplot2, writing colour = "red" inside aes() instead of outside it:

  1. Colours the points red and suppresses every legend
  2. Gives an error
  3. It makes a legend entry 'red', not red points
  4. Has no effect
Answer and working

C. It makes a legend entry 'red', not red points

Inside aes() the string is treated as a data value; outside it sets a fixed colour.

Question 7 · hard

Why do ggplot2 plots usually need data in long (tidy) form?

  1. ggplot2 cannot read numbers in wide form
  2. Long form uses less memory
  3. Wide form cannot be saved
  4. Each aesthetic maps to one column
Answer and working

D. Each aesthetic maps to one column

Mapping colour to year needs a year column, not one column per year.

Question 8 · medium

A unit test for a variance function might check that the values 1, 2, 3, 4, 5 give:

  1. 2
  2. 2.5
  3. 1.58
  4. 3
Answer and working

B. 2.5

Σ(x − 3)² = 10; 10/(5 − 1) = 2.5; 2 divides by n.

Question 9 · medium

A minimal reproducible example helps debugging mainly because it:

  1. Makes the program run faster
  2. It isolates the cause in minimal code
  3. Removes the need for tests
  4. Hides confidential data
Answer and working

B. It isolates the cause in minimal code

Stripping away the irrelevant often reveals the bug.

Question 10 · medium

Replacing the number 12.5 in several formulas with a named constant plot_area_m2 mainly:

  1. Speeds up arithmetic
  2. Is required by the compiler
  3. Clearer, easier-to-change code
  4. Removes rounding errors
Answer and working

C. Clearer, easier-to-change code

Magic numbers hide meaning and invite inconsistent edits.

A study plan for Programming for Statistics & Data (R and Python) in Royal Statistical Society professional awards

This plan follows where our questions actually fall, so the time goes where the marks are likely to be. It is our reading of the syllabus, not the exam body's weighting.

  1. First, the heavy units (57% of the 21 questions): Graphics in R (base and ggplot2) and Python (matplotlib) (4, 19%); R: vectors, data frames, factors and lists (4, 19%); Reading, cleaning and reshaping data (4, 19%).

    Read the manual chapters for these first and do every worked question you can find on them.

  2. Then the middle band: Debugging, testing and code style (3, 14%); Python: core types, NumPy arrays and pandas data frames (2, 10%); R: functions, control flow and vectorisation (2, 10%).

    Aim for one sitting per unit, then mixed questions across them.

  3. Then the lighter units: Writing functions and simple packages (2, 10%).

    Learn the definitions, classifications and standard numbers; these units are more often recalled than worked.

  4. Leave time for the hard ones: Graphics in R (base and ggplot2) and Python (matplotlib) (1 hard of 4), R: vectors, data frames, factors and lists (1 hard of 4).

    Come back to these after a first pass, untimed, and read every explanation, including for the options you rejected.

  5. Bank the easy marks: Reading, cleaning and reshaping data (2 easy of 4); Graphics in R (base and ggplot2) and Python (matplotlib) (1 easy of 4).

    Do these early in revision so they are fast on the day.

  6. Finish timed. Sit the subject as a timed set without notes, mark it, and send each wrong answer back to its unit above.

Last updated · How Laisha writes and checks its pages · Report a mistake

Ask Laisha about this

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

Unlock every question — Royal Statistical Society professional awards Programming for Statistics & Data (R and Pyt

US$10 a month · one price worldwide · cancel any time

  • Every practice question in this subject, with full working
  • Timed exam papers and progress by unit
  • Ask Laisha to explain any answer — up to 1,000 questions a month
Free or Smarter
FreeSmarter
Grow guides, pest pages, articlesRead allRead all
Ask Laisha5 a dayUp to 1,000 a month
Exam practiceThe sample on each pageEvery question, timed papers
Crop calendar and pest alerts—For your own fields
Calculators and tools—All
Uploads and reports—100 a month, real files
10 days free for every new account, no card.