Created
November 13, 2023 12:24
-
-
Save PietrH/8ca7c8ba61d954d164d7164c45d47b71 to your computer and use it in GitHub Desktop.
Rename columns in a data.frame based on a second data.frame as a lookup table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first_df <- tibble::tibble(ids = c("id1", "id2", "id3"), labels = c("label1", "label2", "label3")) | |
second_df <- tibble::tibble(id1 = 1:3, id2 = 3:5, id3 = letters[6:8]) | |
dplyr::rename_with(second_df, ~ first_df$labels[match(.x, first_df$ids)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment