Quick start with R: Symbol sizes in qplot (Part 24)

In Blog 24, let’s see how to use qplot to map symbol colour to a categorical variable. Copy in the following dataset (a medical dataset relating to patients in a randomised controlled trial): M <- structure(list(PATIENT = structure(c(32L, 15L, 41L, 42L, 44L, 17L, 31L, 10L, 38L, 18L, 22L, 30L), .Label…

Quick start with R: Using qplot() function (Part 23)

In Part 23, let’s see how to use qplot to create a simple scatterplot. The qplot (quick plot) system is a subset of the ggplot2 (grammar of graphics) package which you can use to create nice graphs. It is great for creating graphs of categorical data, because you can map…

Quick start with R: Mathematical expressions for graphs (Part 22)

In Blog 22, let’s see how to create mathematical expressions for your graph. Mathematical expressions on graphs are made possible through expression(paste()) and substitute(). If you need mathematical expressions as axis labels, switch off the default axes and include Greek symbols by writing them out in English. You can create…

Rsample (Part 1) – Bootstrap estimate of a confidence interval for a mean

The [su_label]Rsample[/su_label] package contains functions that allow different types of resampling (e.g. cross-validation, bootstrap, etc.). The data structure in which resampling data is stored is a data frame and is very convenient for further work. You can read more about the [su_label]Rsample[/su_label] package on the official package page: https://github.com/tidymodels/rsample. The…

Quick start with R: Recoding (Part 20)

You can re-code an entire vector or array at once. To illustrate, let’s set up a vector that has missing values. A <- c(3, 2, NA, 5, 3, 7, NA, NA, 5, 2, 6) A We can re-code all missing values by another number (such as zero) as follows: A[…

Quick start with R: Count values within cases (Part 19)

SPSS has the Count Values within Cases option, but R does not have an equivalent function. Here are two functions that you might find helpful, each of which counts values within cases inside a rectangular array. For example, you might have a dataset consisting of responses to a questionnaire involving…

Quick start with R: Conditional counting (Part 17)

Counting elements in a dataset Combining the length() and which() commands gives a handy method of counting elements that meet particular criteria. b <- c(7, 2, 4, 3, -1, -2, 3, 3, 6, 8, 12, 7, 3) b Let’s count the 3s in the vector b. count3 <- length(which(b ==…