Created
September 11, 2018 13:46
-
-
Save christianwish/6f74406d4dd04f6cf40791820b16a4f4 to your computer and use it in GitHub Desktop.
map functions for R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.i <- function(fn, data) { | |
result <- c() | |
index <- 1 | |
for (value in data){ | |
result[index] <- fn(value, index) | |
index <- index + 1 | |
} | |
return(result) | |
} | |
map <- function(fn, data) { | |
result <- c() | |
index <- 1 | |
for (value in data){ | |
result[index] <- fn(value) | |
index <- index + 1 | |
} | |
return(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment