简体   繁体   中英

r import excel sheets from file if sheet contain specific value in specific column

I am importing into r multiple similarly structured sheets from a single excel file but would like to know how to adapt below to only import those sheets that contain (among other values) a certain value in a specific column (column = sport, value = football)

excel_sheets("mydata") %>%
  map_df(~read_xlsx("mydata", .x)

Is it possible to adapt my code to do this?

This will include the sheet if sport column has at least one value of 'football' .

library(readxl)
library(purrr)

excel_sheets("mydata") %>%
  map_df(~{
    tmp <- read_xlsx("mydata", .x)
    if(any(tmp$sport %in% 'football')) tmp
    })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM