In the exercises below we practice the basics of visualization in R. Firstly, we use the command: plot . Then we will see how to add information to our plot through command: lines . We will use the mtcars dataset, provided by R Cran (we can upload dataset by type mtcars and then attach our […]

## Get-your-stuff-in-order exercises

In the exercises below we cover the basics of ordering vectors, matrices and data frames. We consider both column-wise and row-wise ordering, single and multiple variables, ascending and descending sorting, and sorting based on numeric, character and factor variables. Before proceeding, it might be helpful to look over the help pages for the sort, order, […]

## Bind exercises

Binding vectors, matrices and data frames using rbind and cbind is a common R task. However, when dimensions or classes differ between the objects passed to these functions, errors or unexpected results are common as well. Sounds familiar? Time to practice! Answers to the exercises are available here. Exercise 1 Try to create matrices from […]

## Practical uses of R object modes: some examples

One of our readers commented on our mode exercises post: “What real world tasks are you using mode to solve?” I think it’s an interesting question, from a somewhat larger perspective. Obviously, it’d be a waste of time to learn all kinds of obscure commands that don’t have a clear application in the real world. […]

## Mode exercises

In the exercises below we cover the basics of R object modes. Understanding mode is important, because mode is a very basic property of any R object. Practically, you’ll use the mode property often to convert e.g. a character vector to a numeric vector or vice versa. Before proceeding, first read section 3.1 of An […]

## functions exercises

Today we’re practicing functions! In the exercises below, you’re asked to write short R scripts that define functions aimed at specific tasks. The exercises start at an easy level, and gradually move towards slightly more complex functions. Answers to the exercises are available here. If you obtained a different solution than the one posted on […]

## Conditional execution exercises

In the exercises below we cover the basics of conditional execution. In all previous exercises, the solutions required one or more R statements that were all executed consecutively. In this series of exercises we’re going to use the if, else and ifelse functions, to execute only a subset of the R script, depending on one […]

## Scan exercises

In the exercises below we cover the basics of the scan function. Before proceeding, first read section 7.2 of An Introduction to R. Answers to the exercises are available here. For each exercise we provide a data set that can be accessed through the link shown in the exercise. You can scan the data from […]

## Reading delimited data

In the exercises below we cover the basics of reading delimited data. Before proceeding, first read section 7.1 of An Introduction to R, and the help pages for the read.table function. Answers to the exercises are available here. For each exercise we provide a data set that can be accessed through the link shown in […]

## Data frame exercises

In the exercises below we cover the basics of data frames. Before proceeding, first read section 6.3.1 of An Introduction to R, and the help pages for the cbind, dim, str, order and cut functions. Answers to the exercises are available here. Exercise 1 Create the following data frame, afterwards invert Sex for all individuals. […]