subset list of multiple dataframe based on either row or column match
问题 library(tidyverse) library(dplyr) list of data frames where some have matches to the vector and some don't lsdf <- list( list1 = head(mtcars), list2 = as.data.frame(t(head(mtcars))) %>% rownames_to_column(., var = "ID"), list3 = head(starwars) ) the vector of names that match to some dataframe vec <- c("mpg", "wt", "am") If I have to manually do it step by step this would be like this. df1 <- lsdf$list1 %>% select(vec) # column-name matches df2 <- lsdf$list2 %>% filter(ID %in% vec) # values