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.
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?
11 22 13 24
11 22 3 4
11 22
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:
isTRUE(all.equal(0.1 + 0.2, 0.3))
as.integer(0.1 + 0.2) == 0.3
round(0.1 + 0.2) == 0.3
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?
lapply(yield, mean)
apply(yield, 1, mean)
mean(yield, variety)
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:
Missing yields in some of the plots in the yield table
Duplicated plot keys in the treatment table
Wrong column types
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?
Counting missing values per column
Checking ranges and types
Printing the first value of each column only
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:
Colours the points red and suppresses every legend
Gives an error
It makes a legend entry 'red', not red points
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?
ggplot2 cannot read numbers in wide form
Long form uses less memory
Wide form cannot be saved
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:
2
2.5
1.58
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:
Makes the program run faster
It isolates the cause in minimal code
Removes the need for tests
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:
Speeds up arithmetic
Is required by the compiler
Clearer, easier-to-change code
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.
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.
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.
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.
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.
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.
Finish timed. Sit the subject as a timed set without notes, mark it, and send each wrong answer back to its unit above.