How to use Function in R