Simon Wallace

8 minute read

How to speak R

Now we will start to cover the basics of programming using R, starting with syntax before moving onto variables. As we shall be writing code I will provide a link where the code written here can be downloaded at the end. However as we previously covered how to create a new script, and you should have an R project already created, you can create a new script and code along as you read if you prefer.

Err… to R! - The IDE

We need somewhere to run our code.

Simon Wallace

5 minute read

The IDE is where we code, the foundation on which we build.

In order for us to be able to code we require an environment in which we can do so. This post outlines how to install R and R Studio - a recommended user interface for R - before presenting components within so you are accustomed to the R environment. Installing R In order to code in R, we first need to install it from the The Comprehensive R Archive Network (CRAN).

Err... to R! - Overview

The house that code built.

Simon Wallace

4 minute read

The house that code built

When it comes to the analysis of data, there has never been a “correct” tool. Social Scientists tend to prefer products like Matlab, SPSS, SAS etc, Computer Scientists tend to prefer Python, and Statisticians tend to prefer R. All of these tools are suitable to perform data analysis, and all have their positives and negatives. R isn’t perfect, the load in times for data are frustrating at times and the learning curve is steep; however it is a powerful and flexible tool for data analysis.

Simon Wallace

6 minute read

With the new year upon us it is a time to reflect on the past twelve months and think about how we are going to melt away all those holiday calories. This time last year I set a goal which was to get 52 running days in a year with a minimum of a 5k run, whilst I didn’t complete this goal in 2017 it motivated me to see how my performance fluctuated over the course of a year.

Simon Wallace

2 minute read

I was working with Tableau one day and saw that they had a calendar heatmap, thinking I might get use of that someday I built it in ggplot2. Required functions library(tidyverse) getMonthWeek <- function(dates,weekStart=c('Monday','Sunday')){ match.arg(weekStart) out <- list() if(weekStart=='Monday'){ dowNumber <- data.frame('Day'=c('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'),'DayNumber'=1:7) }else{ dowNumber <- data.frame('Day'=c('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),'DayNumber'=1:7) } for(month in unique(dates$Month)){ temp <- filter(dates,Month==month) temp$MonthWeek <- 0 temp$MonthWeek[temp$Day==weekStart] <- 1 temp$MonthWeek <- cumsum(temp$MonthWeek)+1 out[[length(out)+1]] <- temp } final <- merge(do.call(rbind,out),dowNumber) final <- final[order(final$Date),] final$Day <- factor(final$Day,levels=dowNumber$Day) final$Month <- factor(final$Month,levels=c('January','February','March', 'April','May','June','July','August', 'September','October','November','December')) final$YearWeek <- 0 final$YearWeek[final$Day==weekStart] <- 1 final$YearWeek <- cumsum(final$YearWeek)+1 return(final) } getCalendar <- function(start,end,weekStart='Monday'){ # Only works with dates in the format %Y-%m-%d dates <- seq(start, end, by="+1 day") days <- weekdays(dates) month <- months(dates) year <- unlist(lapply(strsplit(as.