rr-rio

How to filter and edit the data in R?


What I want to do- First read xlsx file with multiple sheets (say 50). Then filter that file out to keep only 8 sheets out of those.

I used rio package for it. See the code:

#Get the Data
Data = import_list("/Users/Data.xlsx");

Here I am trying to keep only those tabs which I need. However, this code keeps ONLY Tab1 and not all 8.

Data1 = Data [factorize("Tab1", "Tab2", "Tab3", "Tab4", "Tab5","Tab6", "Tab7", "Tab8")]; 

What would be the correct command in order to keep all 8 tabs in Data1?

You can tell any other package I can use as well.


Solution

  • Have you tried this:

    Data1 <-Data[c("Tab1", "Tab2", "Tab3", "Tab4", "Tab5","Tab6", "Tab7", "Tab8")]
    

    Or if you just want to pick up the first 8 worksheets:

    Data1 <- Data[c(1:8)]