Given a tibble "cars"
cars |>
rename_with(~paste0(.x, ")"), .cols = (2:10))
appends a parenthesis to the names columns 2 to 10 of the tibble. How would one go about selecting from the second to the last column? I have accomplished it with
rename_with(~paste0(.x, ")"), .cols = (2:ncol(betterLifeIndicators)))
but I am sure there must be an elegant way to do it within the dyplr package. I was also wondering if there is a way to select all columns except the first (or any other specified set).
Thank you in advance!
>Solution :
Let me know if this works.
# Last column
cars |>
rename_with(~paste0(.x, ")"), .cols = last_col())
# 2nd to Last column
cars |>
rename_with(~paste0(.x, ")"), .cols = 2:last_col())
# All but first (same as above)
cars |>
rename_with(~paste0(.x, ")"), .cols = -1)