Advanced R functions