Paired comparison between rows (or columns)

Hello, I'm new here.
This is probably a basic request, but I couldn't find the solution.

I'm looking to make pairwise comparisons for each posible row combination. I did it using for() like this:

for (i in 1:nrow()) {
    for (j in 1:nrow()) { funtion}}

But I'm looking a method to avoid using for() or if().
If anyone could help I would be very grateful.
Gera.

suppressPackageStartupMessages({
  library(tidyr)
  library(magrittr)
})

dat <- data.frame(item1 = letters,item2 = LETTERS)
dat %>% expand(item1,item2)
#> # A tibble: 676 x 2
#>    item1 item2
#>    <chr> <chr>
#>  1 a     A    
#>  2 a     B    
#>  3 a     C    
#>  4 a     D    
#>  5 a     E    
#>  6 a     F    
#>  7 a     G    
#>  8 a     H    
#>  9 a     I    
#> 10 a     J    
#> # … with 666 more rows
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.