I have this kind of dataset
mtcars$drat1 = mean(mtcars$drat)
mtcars$wt1 = mean(mtcars$wt)
I have been trying to build up the code following the rule so that it selects the every element finishing with t and a number.
I have tried this code but I am getting an empty object.
mtcars %>% dplyr::select(ends_with('t[0-9]$'))
How should I modify this?
As the documentation states, the argument for
starts_with(),ends_with(), andcontains()looks for an exact match. You want to usematches()here, which can accept regex:Or in base R: