We can create a string identifier that captures a given pair of countries independent of their ordering:
library( tidyverse )
# Original data
X <- data_frame(C1 = c("US", "FR", "US", "DE", "US", "US", "RU", "FI"),
C2 = c("FR", "US", "DE", "US", "RU", "FI", "FI", "RU"))
# Creates an order-independent string ID for each entry
Y <- X %>% mutate( S = map2_chr( C1, C2, ~str_flatten(sort(c(.x,.y))) ) )
# # A tibble: 8 x 3
# C1 C2 S
# <chr> <chr> <chr>
# 1 US FR FRUS
# 2 FR US FRUS
# 3 US DE DEUS
# 4 DE US DEUS
# 5 US RU RUUS
# ...
We can then use these string identifiers to find pairs of countries that occur in both directions (e.g., US > FR and FR > US). These pairs will have two matching string IDs.
# Identify string IDs with both orderings and assign an integer ID to each
Z <- Y %>% group_by(S) %>% filter( n() == 2 ) %>% ungroup %>% # Keep groups of size 2
select(S) %>% distinct %>% mutate( PairID = 1:n() ) # Annotate unique values
# # A tibble: 3 x 2
# S PairID
# <chr> <int>
# 1 FRUS 1
# 2 DEUS 2
# 3 FIRU 3
All that's left to do is join the new string ID -> integer ID map against the original data, and replace NAs with "-":
left_join( Y, Z ) %>% select(-S) %>% mutate_at( "PairID", replace_na, "-")
# # A tibble: 8 x 3
# C1 C2 PairID
# <chr> <chr> <chr>
# 1 US FR 1
# 2 FR US 1
# 3 US DE 2
# 4 DE US 2
# 5 US RU -
# 6 US FI -
# 7 RU FI 3
# 8 FI RU 3