mercredi 29 novembre 2017

R tribble rename columns with regular expressions

I have multiple duplicated columns in a table after several dplyr::joins. A simple version of the table looks like this:

col1 col2 col3 col4.x col4.y col5.x col5.y

I want to get to rename to:

col1 col2 col3 col4 col5

I was able to remove the .y columns with select(tablename, -matches(".y"))

Resulting in:

col1 col2 col3 col4.x col5.x

From here, I am thinking the rename_if() should work, but I am at a loss as to how to get col4.x and col5.x renamed to col4 and col5.

Any advice would be appreciated.

Aucun commentaire:

Enregistrer un commentaire