fixed bug in R code