R code bachelor project