Publications by Han de Vries
Data table exercises: keys and subsetting
The data.table package is a popular R package that facilitates fast selections, aggregations and joins on large data sets. It is well-documented through several vignettes, and even has its own interactive course, offered by Datacamp. For those who want to build some mileage practising the use of data.table, there’s good news! In the coming week...
2800 sym 2 img
Celebrating our 100th R exercise set
Yesterday we published our 100th set of exercises on R-exercises. Kudos and many thanks to Avi, Maria Elisa, Euthymios, Francisco, Imtiaz, John, Karolis, Mary Anne, Matteo, Miodrag, Paritosh, Sammy, Siva, Vasileios, and Walter for contributing so much great material to practice R programming! Even more thanks to Onno, who is working (largely) beh...
4409 sym 2 img
How to create your first vector in R
Are you an expert R programmer? If so, this is *not* for you. This is a short tutorial for R novices, explaining vectors, a basic R data structure. Here’s an example: 10 150 30 45 20.3 And here’s another one: -5 -4 -3 -2 -1 0 1 2 3 still another one: "Darth Vader" "Luke Skywalker" "Han Solo" and our final example: 389.3491 These examples show...
2701 sym R (292 sym/6 pcs) 2 img
Creating vectors
A vector is the most elementary way to store and structure data in R. For now, think of it as a list of numbers, which can be as short as a single number, or as long as about 2 billion(!) numbers. Perhaps you were used to working with lists of numbers already in a spreadsheet application (E.g., a row or column filled with numbers in Microsoft Exc...
5874 sym 2 img
Working With Vectors
In the previous exercise set we practised vectors as a data structure. As I noted at the beginning of that set, perhaps you were already familiar with data in a vector-like structure in other applications such as Microsoft Excel or SPSS. If so, perhaps you also used those data to carry out calculations. In this set, we’re going to practise all ...
8152 sym 2 img
Vectors and Functions
In the previous set we started with arithmetic operations on vectors. We’ll take this a step further now, by practising functions to summarize, sort and round the elements of a vector. Sofar, the functions we have practised (log, sqrt, exp, sin, cos, and acos) always return a vector with the same length as the input vector. In other words, the ...
12114 sym R (357 sym/3 pcs) 2 img
Regular Sequences
So far in this series, we used vectors from built-in datasets (rivers, women and nhtemp), or created them by stringing together several numbers with the c function (e.g. c(1, 2, 3, 4)). R offers an extremely useful shortcut to create vectors of the latter kind, which is the colon : operator. Instead of having to type: x <- c(1, 2, 3, 4) we can si...
7443 sym 2 img