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. For other parts of this series please follow the tag: dataframes. Exercise 1 […]

## List exercises

In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the sum, length, strsplit, and setdiff functions. Answers to the exercises are available here. Exercise 1 If: p Are you a beginner (1 star), intermediate (2 stars) or advanced […]

## Factor exercises

In the exercises below we cover the basics of factors. Before proceeding, first read chapter 4 of An Introduction to R, and the help pages for the cut, and table functions. Answers to the exercises are available here. Exercise 1 If x = c(1, 2, 3, 3, 5, 3, 2, 4, NA), what are the […]

## Index vectors

In the exercises below we cover the basics of index vectors. Before proceeding, first read section 2.7 of An Introduction to R, and the help pages for the sum, and which functions. Answers to the exercises are available here. Exercise 1 If x Are you a beginner (1 star), intermediate (2 stars) or advanced (3 […]

## Character vector exercises

In the exercises below we cover the basics of character vectors. Before proceeding, first read section 2.6 of An Introduction to R, and the help pages for the nchar, substr and sub functions. Answers to the exercises are available here. Exercise 1 If x Are you a beginner (1 star), intermediate (2 stars) or advanced […]

## Missing values

Today we’re training how to handle missing values in a data set. Before starting the exercises, please first read section 2.5 of An Introduction to R. Solutions are available here. Exercise 1 If X Are you a beginner (1 star), intermediate (2 stars) or advanced (3 stars) R user?

## Array exercises

Exercise 1 Create an array (3 dimensional) of 24 elements using the dim() function. Exercise 2 Create an array (3 dimensional) of 24 elements using the array() function. Exercise 3 Assign some dimnames of your choice to the array using the dimnames() function. Exercise 4 Assign some dimnames of your choice to the array using […]

## Matrix exercises

Please note, solutions are available here. Exercise 1 Create three vectors x,y,z with integers and each vector has 3 elements. Combine the three vectors to become a 3×3 matrix A where each column represents a vector. Change the row names to a,b,c. Think: How about each row represents a vector, can you modify your code […]

## Logical vectors and operators

Before you start, enter the following code: data <- mtcars Solutions are available here. Exercise 1 Use logical operators to output only those rows of data where column mpg is between 15 and 20 (excluding 15 and 20). Exercise 2 Use logical operators to output only those rows of data where column cyl is equal […]