Skip to content

Instantly share code, notes, and snippets.

@danlewer
Last active January 29, 2023 21:48
Show Gist options
  • Save danlewer/a473b1f871f0fa55ea0201e4c1187fc4 to your computer and use it in GitHub Desktop.
Save danlewer/a473b1f871f0fa55ea0201e4c1187fc4 to your computer and use it in GitHub Desktop.
# return a table, but specify the values you want to be tabulated
# works like base::table, but supplies only specified values, and returns 0 if none of those values exist in the vector
tab_specific_values <- function(vector, values = unique(vector)) `names<-`(rowSums(outer(values, vector, `==`)), values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment