I have a list of sheet_names:
path<-paste0("wd", sheets$file[1:nrow(sheets)])
sheet_names<-lapply(path, readxl::excel_sheets)
I want to keep only relevant sheets from the list of sheet_names
which match the data frame column sheets$table_n
I have tried mapply
and grepl
, but the error I get is that length > 1 and only the first element will be used:
rel_sheets<- sheet_names[grepl(toString(sheets$table_n[1:nrow(sheets)]),sheet_names)]
I have also tried using which, but it doesn't return a list:
rel_sheets<- sheet_names[which((sheets$table_n %in% sheet_names)==TRUE)]
Any suggestions with tidyverse would be much appreciated thanks.
question from:
https://stackoverflow.com/questions/65936496/filter-a-list-by-matches-with-column-in-a-data-frame 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…