R code for my research