Skip to content

Instantly share code, notes, and snippets.

@christianwish
Created September 11, 2018 13:46
Show Gist options
  • Save christianwish/6f74406d4dd04f6cf40791820b16a4f4 to your computer and use it in GitHub Desktop.
Save christianwish/6f74406d4dd04f6cf40791820b16a4f4 to your computer and use it in GitHub Desktop.
map functions for R
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