Join multiple files from a folder in R

4

I'm trying to join multiple xlsx files in R. To do this, first open the following libraries and use the programming:

library(readxl)
library(plyr)
larquivos<-list.files("C:\Users\tomas.veiga\Documents\Financeiro\dados",full.names=TRUE)
arquivos <- lapply(larquivos, function(x) read_excel(path = x, sheet = 1))

Since the files have a difference in the number of lines, I try to do the following:

extracontab<-data.frame(rbind.fill(arquivos[c(1:12)]))

But there is an error:

Error in vector(type, length) :   vector: cannot make a vector of mode 'NULL'.

I also try to do this:

extracontab<-data.frame(rbind.fill(arquivos[c(1:12)]))

But nothing works. What should I do? Thank you.

    
asked by anonymous 09.12.2016 / 12:29

2 answers

4

I was able to reproduce your error using a spreadsheet with an empty column name. That's probably his problem.

To solve it I would do it like this:

arquivos <- lapply(larquivos, function(x) {
  df <- read_excel(path = x, sheet = 1)
  names(df)[names(df) == ""] <- "x__"
  return(df)
})

And then I'd call rbind.fill the same way you're doing. The rows I added only change the name of the blank columns to "x__". You may prefer another action such as deleting them, entering another name, and so on. To do this, simply modify the function called by lapply .

    
09.12.2016 / 17:32
0

I did it this way:

larquivos<-list.files("C:/Users/tomas.veiga/Documents/Financeiro/dados",full.names=TRUE)
arquivos <- sapply(larquivos, read_excel,simplify = F)
dados <- rbindlist(arquivos, idcol = "id")

And then I removed the columns I wanted.

    
13.12.2016 / 19:37