# R

## 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 multiple Likert items scored 1 …

## Quick start with R: Using any() and all() commands (Part 18)

Test for the existence of particular values using the any() and all() commands Create a vector b: b

## 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 == 3)) count3 In fact, you …

## Quick start with R: Generalised Linear Model on binary data (Part 16)

In Part 15, we saw how to create a simple Generalised Linear Model on binary data using the glm() command. We continue with the same glm (modelling the vs variable on the weight and engine displacement) on the same data set – the mtcars dataset – which is built into R. model

## Quick start with R: Generalised Linear Models (Part 15)

In Part 15, let’s see how to create simple Generalised Linear Models in R. Ordinary Least Squares regression provides linear models of continuous variables. However, much data of interest to statisticians and researchers are not continuous and so other methods must be used to create useful predictive models. The glm() command is designed to perform …

## Quick start with R: Pie charts (Part 14)

In Part 14, let’s see how to create pie charts in R. Let’s create a simple pie chart using the pie() command. As always, we set up a vector of numbers and then we plot them. B <- c(2, 4, 5, 7, 12, 14, 16) Create a simple pie chart. pie(B) Now let’s create a …

## Quick start with R: Box plots (Part 13)

In Part 13, let’s see how to create boxplots in R. Let’s create a simple boxplot using the boxplot() command, which is easy to use. First, we set up a vector of numbers and then we plot them. Boxplots can be created for individual variables or for variables by group. The syntax is boxplot(x, data=), …

## Quick start with R: Histograms (Part 12)

In Part 12, let’s see how to create histograms in R. Let’s create a simple histogram using the hist() command, which is easy to use, but actually quite sophisticated. First, we set up a vector of numbers and then we create a histogram. B <- c(2, 4, 5, 7, 12, 14, 16) hist(B) That was …

## Quick start with R: Bar charts (Part 11)

In Part 11, let’s see how to create bar charts in R. Let’s create a simple bar chart using the barplot() command, which is easy to use. First, we set up a vector of numbers. Then we count them using the table() command, and then we plot them. The table() command creates a simple table …

## Quick start with R: aggregate() command (Part 10)

In Part 10, let’s look at the aggregate() command for creating summary tables using R. You may have a complex dataset that includes categorical variables of several levels, and you may wish to create summary tables for each level of the categorical variable. For example, your dataset may include the variable Gender, a two-level categorical …