0

I am importing multiple excel workbooks, processing them, and appending them subsequently. I want to create a temporary dataframe (tempfile?) that holds nothing in the beginning, and after each successive workbook processing, append it. How do I create such temporary dataframe in the beginning?

I am coming from Stata and I use tempfile a lot. Is there a counterpart to tempfile from Stata to R?

Bush
  • 1
  • 1
  • 3
    While the question is different, the answer here should do what you need: https://stackoverflow.com/a/42344644/269476. However, you don't need to initialise with an empty data.frame, you could start with your first file. – James Sep 19 '19 at 11:02
  • https://stackoverflow.com/q/11433432/1412059 – Roland Sep 19 '19 at 11:09

1 Answers1

0

As @James said you do not need an empty data frame or tempfile, simply add newly processed data frames to the first data frame. Here is an example (based on csv but the logic is the same):

list_of_files <- c('1.csv','2.csv',...)

pre_processor <- function(dataframe){
    # do stuff
}

library(dplyr)

dataframe <- pre_processor(read.csv('1.csv')) %>%
    rbind(pre_processor(read.csv('2.csv'))) %>%>
    ...

Now if you have a lot of files or a very complicated pre_processsing then you might have other questions (e.g. how to loop over the list of files or to write the right pre_processing function) but these should be separate and we really need more specifics (example data, code so far, etc.).

Fnguyen
  • 1,159
  • 10
  • 23