I was wondering what the code below does.
data=mydata[,names(mydata) %in% variables$variable]
It subsets the columns of ‘mydata’ that are also found in the variable column in ‘variables’. It can be also written as
library(dplyr) mydata %>% select(any_of(variables$variable))