extract the columns in a data frame when colnames match characters in a vector

We can use select

library(dplyr)
df %>%
   select(all_of(v))

-output

#     a   c
#1  26  92
#2  34  15
#3  15  80
#4   4  88
#5  55  69
#6  96  78
#7  63   2
#8  69  62
#9  12 100
#10 16  22

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top