In Stata, if I have these variables: var1
, var2
, var3
, var4
, var5
, and var6
, I can select all of them with the command var*
. Does R have a similar functionality?
The select
function from the "dplyr" package offers several flexible ways to select variables. For instance, using @Marius's sample data, try the following:
library(dplyr)
df %>% select(starts_with("var")) # At the start
df %>% select(num_range("var", 1:3)) # specifying range
df %>% select(num_range("var", c(1, 3))) # gaps are allowed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With