Grouping objects into clusters is a frequent task in data analysis. In this set of exercises we will use hierarchical clustering to cluster European capitals based on their latitude and longitude. Before trying out this exercise please make sure that you are familiar with the following functions: dist, hlcust, cutree, rect.hclust We will be using […]

## Hierarchical Clustering solutions (beginner)

Below are the solutions to these exercises on hierarchical clustering. # Prepare dataset library(ggmap) capitals <- c("Albania, Tirana", "Andorra, Andorra la Vella", "Armenia, Yerevan", "Austria, Vienna", "Azerbaijan, Baku", "Belarus, Minsk", "Belgium, Brussels", "Bosnia and Herzegovina, Sarajevo", "Bulgaria, Sofia", "Croatia, Zagreb", "Cyprus, Nicosia", "Czech Republic, Prague", "Denmark, Copenhagen", "Estonia, Tallinn", "Finland, Helsinki", "France, Paris", "Germany, Berlin", […]

## Replicating Plots – Boxplot Exercises

R’s boxplot function has a lot of useful parameters allowing us to change the behaviour and appearance of the boxplot graphs. In this exercise we will try to use those parameters in order to replicate the visual style of Matlab’s boxplot. Before trying out this exercise please make sure that you are familiar with the […]

## Replicating Plots – Boxplot Solutions

Below are the solutions to these exercises on boxplot parameters. ############### # # # Exercise 1 # # # ############### boxplot(Sepal.Width ~ Species, data=iris) ############### # # # Exercise 2 # # # ############### boxplot(Sepal.Width ~ Species, data=iris, ylim=c(2, 4.5)) ############### # # # Exercise 3 # # # ############### boxplot(Sepal.Width ~ Species, data=iris, ylim=c(2, […]

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

## Combinations Solutions

Below are the solutions to these exercises on combinations. ############### # # # Exercise 1 # # # ############### expand.grid(c(“H”,”T”), 1:6) ## Var1 Var2 ## 1 H 1 ## 2 T 1 ## 3 H 2 ## 4 T 2 ## 5 H 3 ## 6 T 3 ## 7 H 4 ## 8 T […]

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

## Higher Order Functions Solutions

Below are the solutions to these exercises on higher order functions. ############### # # # Exercise 1 # # # ############### multidata <- list(mtcars, USArrests, rock) Map(summary, multidata) ## [[1]] ## mpg cyl disp hp ## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0 ## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: […]