The lapply() function applies a function to individual values of a list, and is a faster alternative to writing loops. Structure of the lapply() function: lapply(LIST, FUNCTION, …) The list variable used for these exercises: list1 <- list(observationA = c(1:5, 7:3), observationB=matrix(1:6, nrow=2)) Answers to the exercises are available here. Exercise 1 Using lapply(), find […]

# Exercises

## Network Analysis Part 1 Exercises

In this set of exercises we shall create an empty graph and practice the functions for basic manipulation with vertices and edges, using the package igraph. If you don’t have the package already installed, install it using the following code: install.packages(“igraph”) and load it into the session using the following code: library(“igraph”) before proceeding. You […]

## Independent t test in R

The independent t test is used to test if there is any statistically significant difference between two means. Use of an independent t test requires several assumptions to be satisfied. The assumptions are listed below The variables are continuous and independent The variables are normally distributed The variances in each group are equal When these […]

## Efficient Processing With Apply() Exercises

The apply() function is an alternative to writing loops, via applying a function to columns, rows, or individual values of an array or matrix. The structure of the apply() function is: apply(X, MARGIN, FUN, …) The matrix variable used for the exercises is: dataset1 <- cbind(observationA = 16:8, observationB = c(20:19, 6:12)) Answers to the […]

## Examining Data Exercises

One of the first steps of data analysis is the descriptive analysis; this helps to understand how the data is distributed and provides important information for further steps. This set of exercises will include functions useful for one variable descriptive analysis, including graphs. Before proceeding, it might be helpful to look over the help pages […]

## Fundamental and Technical Analysis of Shares Exercises

In this set of exercises we shall explore possibilities for fundamental and technical analysis of stocks offered by the quantmod package. If you don’t have the package already installed, install it using the following code: install.packages(“quantmod”) and load it into the session using the following code: library(“quantmod”) before proceeding. Answers to the exercises are available […]

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

This is the second part in the series teaching the “lubridate” package. As a short recap from the previous part, I mentioned that date/date_time formats are easily parced using the ymd set of functions (for example, dmy, ymd_h, etc). I also explained that arithmetic calculations are performed using the days, months, years, etc. functions. In […]

## Reshape 2 Exercises

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