Created
          December 19, 2017 22:36 
        
      - 
      
- 
        Save sahilseth/80e329ab1d2cbc98a6b4c18ffcb2e992 to your computer and use it in GitHub Desktop. 
    expand_grid
  
        
  
    
      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
    
  
  
    
  | #' 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