The Reshape 2 package is based on differentiating between identification variables, and measurement variables. The functions of the Reshape 2 package then “melt” datasets from wide to long format, and “cast” datasets from long to wide format. Required package: library(reshape2) Answers to the exercises are available here. Exercise 1 Set a variable called “moltenMtcars“, by […]

## Using MANOVA to Analyse a Banking Crisis Exercises

In this set of exercises we will practice multivariate analysis of variance – MANOVA. We shall try to find if there is a difference in the combination of export and bank reserves, depending on the status of banking sector (is there a crisis or not). The data set is fictitious and servers for education purposes […]

## Matrix Operations Exercises

This set of exercises will help you to learn and test your skill in matrix operations, starting with basic ones like scalar multiplication all the way through eigenvalue and eigenvectors. Before proceeding, it might be helpful to look over the help pages for the diag, t, eigen, and crossprod functions. If you want further documentation […]

## Dates and Times – Simple and Easy with lubridate exercises (part 1)

As in any programming language, handling date and time variables can be quite frustrating, since, for example, there is no one single format for dates, there are different time zones and there are issues such as daylight saving time. Base R provides several packages for handling date and time variables, but they require mastering cumbersome […]

## Combinations Exercises

When doing data analysis it happens often that we have a set of values and want to obtain various possible combinations of them. For example, taking 5 random samples from a dataset of 20. How many possible 5-sample sets are there and how to obtain all of them? R has a bunch of functions that […]

## Stock Prices Analysis part 3 – Exercises

This is the third and the final part of the exercises dedicated to analysis of stock prices. In this part we will provide exercises for testing the type of distribution of stock prices and analysing and predicting stock prices using ARIMA models. You dont need to be an expert stock’s trader in order to understand […]

## Higher Order Functions Exercises

Higher order functions are functions that take other functions as arguments or return functions as their result. In this set of exercises we will focus on the former. R has a set of built-in higher order functions: Map, Reduce, Filter, Find, Position, Negate. They enable us to complete complex operations by using simple single-purpose functions […]

## Stock prices analysis part 2 exercises

This is the second part of the exercises dedicated to analysis of stock prices. In this part we will provide exercises for plotting, fitting linear model and predicting stock prices. You dont need to be an expert stock’s trader in order to understand the examples, but you should go through part 1, since we shall […]

## Interactive Subsetting Exercises

The function, “subset()” is intended as a convienent, interactive substitute for subsetting with brackets. subset() extracts subsets of matrices, data frames, or vectors (including lists), according to specified conditions. Answers to the exercises are available here. Exercise 1 Subset the vector, “mtcars[,1]“, for values greater than “15.0“. Exercise 2 Subset the dataframe, “mtcars” for rows […]

## Stock prices analysis part 1 exercises

In this set of exercises we are using R to analyse stock prices. This is the first part where we exercise basic descriptive statistics. You dont need to be an expert stock trader in order to understand examples. Where needed, additional explanations will be provided. All examples will be based on real historical data acquired […]