In the exercises below we practice how to personalize graphics parameters, how to produce different plots at the same time and how to save a plot in a file. We will use commands such as par and jpeg. We will use the mtcars dataset, provided by R Cran (we can upload the dataset by typing […]

## Lets Begin with something sample

The following R-exercises constitute the first set in a series of posts aimed to review fundamental probability and (bio)statistics concepts while learning to use R. Today we will focus on generating random numbers from some of the built-in distributions in R as well as using the sample() function to obtain random samples from a given […]

## 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 weeks, […]

## Customize a scatterplot exercises

In the following exercises we practice how to customize a scatterplot. We will use axis , to add an axis; mtext to add a text; and legend to add a legend. Moreover we practice how to add details in every stage. We will use the mtcars dataset, provided by R Cran (we can upload dataset […]

## Start plotting data!

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 […]