A function that takes two columns in a data frame and reports the unique values of one column associated with the unique values of the other column.

column_by_other(dtf, col1, col2)

Arguments

dtf

A data frame.

col1

The first column (non-standard evaluation possible).

col2

The second column (non-standard evaluation possible).

Value

A data frame with the unique values of the first column associated with the unique values of the second.

Author

Kevin Potter

Examples

# Define a data frame
dtf <- data.frame(
  A = c( 1, 1, 2, 2, 3, 3 ),
  B = c( 'A', 'A', 'B', 'B', 'C', 'D' )
)

# Values of column 'B' by values of column 'A'
column_by_other( dtf, A, B )
#>   A B
#> 1 1 A
#> 2 2 B
#> 3 3 C
#> 4 3 D