Playing around with R code and maths