Skip to content

Instantly share code, notes, and snippets.

@sahilseth
Created December 19, 2017 22:36
Show Gist options
  • Save sahilseth/80e329ab1d2cbc98a6b4c18ffcb2e992 to your computer and use it in GitHub Desktop.
Save sahilseth/80e329ab1d2cbc98a6b4c18ffcb2e992 to your computer and use it in GitHub Desktop.
expand_grid
#' expand_grid
#' @export
expand_grid <- function(x, y, remove_diag = TRUE){
x1 <- seq_along(x)
y1 <- seq_along(y)
ex <- expand.grid(x1, y1)
ex <- ex[ex[,2]>=ex[,1],]
grd <- data.frame(x = x[ex[,1]], y = y[ex[,2]])
# remove where both are the same
if(remove_diag)
grd <- grd[!grd$x == grd$y,]
return(grd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment