Skip to content

Instantly share code, notes, and snippets.

@johnjosephhorton
Created May 21, 2011 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjosephhorton/984918 to your computer and use it in GitHub Desktop.
Save johnjosephhorton/984918 to your computer and use it in GitHub Desktop.
functional programming way to implement a case method in R
# keys and values map 1:1
# e.g.,
keys <- c(1,2,3)
values <- c('a','b','c')
list_of_keys <- c(1,2,3,1,1,2)
letters <- sapply(list_of_keys, function(x){values[which(x==keys)]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment