Factorial rewritten in R