How to mutate columns whose column names differ by a suffix?

Viewed 113

In a dataset like

data_frame(a=letters, a_1=letters, b=letters, b_1=letters)

I would like to concatenate the columns that share a similar "root", namely a with a_1 and b with b_1. The output should look like

# A tibble: 26 x 2
       a     b
   <chr> <chr>
 1   a a   a a
 2   b b   b b
 3   c c   c c
 4   d d   d d
 5   e e   e e
 6   f f   f f
 7   g g   g g
 8   h h   h h
 9   i i   i i
10   j j   j j
# ... with 16 more rows
2 Answers
Related