Publications by David Selby

R code golf: the identity matrix

27.03.2019

How many different ways are there to create an identity matrix in R? This was an interesting little challenge set by Guillaume Nicoulaud on Twitter. Find as many way you can to create the identity matrix with #rstats. pic.twitter.com/HlhIM6mSrx— Guillaume Nicoulaud (@ordrespontane) February 3, 2018 In code golf, programmers try to write an algo...

5936 sym R (2960 sym/19 pcs)

Which film should I watch during lockdown?

06.05.2020

My brother wrote to me this week with an interesting task: I’ve got a list of films I’ve noted down whenever I’ve seen a good review. But it’s hundreds long and I can never remember what a film is from its title and can’t be bothered to look them up each time. Any chance you can knock up a script that cross-references a Rotten Tomatoes...

7018 sym R (3615 sym/9 pcs) 6 img

Which film should I watch during lockdown?

06.05.2020

My brother wrote to me this week with an interesting task: I’ve got a list of films I’ve noted down whenever I’ve seen a good review. But it’s hundreds long and I can never remember what a film is from its title and can’t be bothered to look them up each time. Any chance you can knock up a script that cross-references a Rotten Tomatoes...

7018 sym R (3615 sym/9 pcs) 6 img

Advent of Code 2020

06.12.2020

Advent of Code is a series of programming puzzles you can tackle to hone your coding skills each day in the run-up to Christmas. This year I am attempting it using R, which can make some challenges easier or harder depending on whether they are more ‘computer sciencey’ or more ‘data sciencey’. Generally it makes parsing datasets easier bu...

19753 sym R (19393 sym/56 pcs)

Advent of Code 2020

06.12.2020

Advent of Code is a series of programming puzzles you can tackle to hone your coding skills each day in the run-up to Christmas. This year I am attempting it using R, which can make some challenges easier or harder depending on whether they are more ‘computer sciencey’ or more ‘data sciencey’. Generally it makes parsing datasets easier bu...

6017 sym R (6030 sym/21 pcs)

The unequalled joy of non-equi joins

13.02.2021

A common task in data analysis is to merge or join two tables according to shared keys or values. The operation is perhaps most commonly associated with relational databases and structured query language (SQL) but it’s just as useful in R with data frames. Most joins are equi-joins, matching rows according to two columns having exactly equal va...

5899 sym R (1540 sym/9 pcs) 11 tbl

There are now 3 different R pipes

18.05.2021

R 4.1.0 has been released and has a couple of handy new features. One is a shorthand syntax for defining functions. Now, instead of writing, for example triple <- function(x) x * 3 you can use the more concise syntax triple <- \(x) x * 3 which may come in handy when using anonymous functions in apply-type calls. More interesting, though, is the...

1305 sym R (175 sym/6 pcs)

Advent of Code 2021

01.12.2021

It’s that time of year again. And not just for Secret Santa—it’s time for the Advent of Code, a series of programming puzzles in the lead-up to Christmas. I’m doing the 2021 challenge in R—in the form of an open-source R package, to demonstrate a test-driven workflow. Each puzzle description typically comes with a few simple examples o...

1897 sym R (475 sym/6 pcs)

Indexing from zero in R

06.12.2021

Everybody knows that R is an inferior programming language, because vector indices start from 1, whereas in real programming languages like C and Python, array indexing begins from 0. Sometimes this can be quite annoying if a problem—be it a mathematical algorithm or a coding challenge—calls for zero-based indexing. You find yourself having t...

1645 sym R (226 sym/5 pcs)