[r] R apply function with multiple parameters