Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f <- function(x, y){
- n <- length(x)
- out <- numeric(n)
- for(i in seq_along(x)){
- if(x[i] %% 2 == 0){
- out[i] <- x[i]/y
- } else {
- out[i] <- x[i]*y
- }
- }
- out
- }
- f = function(x, y) {
- evens = (x %% 2) == 0
- x[evens] = x[evens] / y
- x[!evens] = x[!evens] * y
- return(x)
- }
Add Comment
Please, Sign In to add comment