Search code examples
rods

Import multiple tabs from a ODS file using R while specifying exact ranges in each tab


I'm trying to use the library readODS to import a file ('sample data.ods') with 30 tabs. Each tab has the exact same layout and I need to extract the exact same columns from each tab then combine them into 1 DF but I'm finding it difficult to do so. For example, I need to extract rows 5 to 20, with columns 3,5,7,9,11. An example of what I imagine it to look like is below (obviously, this is incorrect!)

my_df <- read_ods('pedestrianfootfall2013.ods', 
              sheet = 1:30, c[3,5,7,9,11], 
              rows(5:20))

And then I'm not sure whether I would use rbind or merge... Thanks


Solution

  • Found a work around...save the file as an Excel file and use the following:

    library(plyr)
    library(XLConnect)
    
    
    df1 <- loadWorkbook('filename.xlsx')
    df1_sheets <- getSheets(df1)
    
    
    
    for (ws in df1_sheets) {
      df2 <- readWorksheet(df1, sheet = 1:52, header=TRUE, startRow = 230, endRow = 254)
    }
    
    
    df2_all <- ldply(df2, rbind)
    df2_Reduced <- df2_all[c(1,2,4,6,8,10,12,14)]