Factor variables in R can be mind-boggling. Often, you can just avoid them and use characters vectors instead – just don’t forget to set stringsAsFactors=FALSE. They are, however, very useful in some circumstances, such as statistical modelling and presenting data in graphs and tables. Relying on factors but misunderstanding them has been known to “eat […]

## Basic Generalized Additive Models In Ecology: Exercises

Generalized Additive Models (GAM) are non-parametric models that add smoother to the data. In this exercise, we will look at GAMs using cubic spline using the mgcv package. Data-sets used can be downloaded here. The data-set is the experiment result of grassland richness over time in the Yellowstone National Park (Skkink et al. 2007). […]

## Melt and Cast The Shape of Your Data-Frame: Exercises

Data-sets often arrive to us in a form that is different from what we need for our modeling or visualization functions, which, in turn, don’t necessarily require the same format. Reshaping data.frames is a step that all analysts need, but many struggle with. Practicing this meta-skill will, in the long-run, result in more time to […]

## Non-Linear Models in R: Exercises

A mechanistic model for the relationship between x and y sometimes needs parameter estimation. When model linearisation does not work,we need to use non-linear modeling. There are three main differences between non-linear and linear modeling in R: 1. Specify the exact nature of the equation. 2. Replace the lm() with nls(), which means non-linear least […]

## Intro To Time Series Analysis – Part 2: Exercises

In the exercises below, we will explore more in the Time Series analysis. The previous exercise can be found here. Please follow this in sequence. Answers to these exercises are available here. Exercise 1 Load the AirPassengers data. Check its class and see the start and end of the series. Exercise 2 Check the cycle of […]

## How To Create a Flexdashboard: Exercises

INTRODUCTION With flexdashboard, you can easily create interactive dashboards for R. What is amazing about it is that with R Markdown, you can publish a group of related data visualizations as a dashboard. Additionally, it supports a wide variety of components, including htmlwidgets; base, lattice, and grid graphics; tabular data; gauges and value boxes […]

## Sharpening the Knives in the data.table Toolbox: Exercises

If knowledge is power, then knowledge of data.table is something of a super power, at least in the realm of data manipulation in R. In this exercise set, we will use some of the more obscure functions from the data.table package. The solutions will use set(), inrange(), chmatch(), uniqueN(), tstrsplit(), rowid(), shift(), copy(), address(), setnames() […]

## How To Create a Flexdashboard

**Please note** This tutorial is largely taken from the relevant package github page **Please note** INTRODUCTION With flexdashboard, you can easily create interactive dashboards for R. What is amazing about it is that with R Markdown, you can publish a group of related data visualizations as a dashboard. Additionally, it supports a wide variety of […]

## Polynomial Model in R – Study Case: Exercises

It is pretty rare to find something that represents linearity in the environmental system. The Y/X response may not be a straight line, but humped, asymptotic, sigmoidal or polynomial are possibly, truly non-linear. In this exercise, we will try to take a closer look at how polynomial regression works and practice with a study case. […]

## Intro To Time Series Analysis – Part 1: Exercises

In the exercises below, we will work with Time Series analysis and see how R can make your life easier when working with Time Series. This will be a series of Exercises and I urge you to take it in series. Please install the package and load the library before starting. Answers to these exercises […]