Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

r - Filter a list by matches with column in a data frame

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...