Read a lot of Excel files from R

This is my first time with R, so maybe the problem is trivial

I need to load the date from xls files from url, and each of them should be in one data frame. For example here .

I decided to use the gdata package (the xlsReadWrite package is not available for R version 3.1.0, RODBC is not available for win64)

Download is great for a single file (year, e.g. 2013)

readxls<-function()
{
  library("gdata")
  link<-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",year,".xls")
  xlsdata <<- read.xls(link, sheet = 1, perl = "C:\\Perl64\\bin\\perl.exe", header=TRUE) 
}

I tried to read a lot of .xls in list () using a loop. (e.g. y_begin = 2012, y_end = 2014)

readxls<-function()
{
  library("gdata")

  ldata<<- list()
  j=1
  for (i in y_begin:y_end)
  {
    link<-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",i,".xls")
    xlsdata <<- read.xls(link, sheet = 1, perl = "C:\\Perl64\\bin\\perl.exe", header=TRUE) 

    ldata[j] <<- xlsdata
    j<-j+1
  }
}

I thought that after that I could combine them, but I don’t know how to get data from one data frame in the list, for example> View (ldata [2]) returns only the first column

+4
source share
2

, . , ldata [[j]]

readxls<-function()
{
  library("gdata")

  ldata<<- list()
  j=1
  for (i in y_begin:y_end)
  {
    link<-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",i,".xls")
    xlsdata <<- read.xls(link, sheet = 1, perl = "C:\\Perl64\\bin\\perl.exe", header=TRUE) 

    ldata[[j]] <<- xlsdata
    j<-j+1
  }
}
0

for, . lapply . R- - ( ). :

library(gdata)
readxls<-function()
{
  ids <- seq(y_begin,y_end)
  links <-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",ids,".xls")

  lapply (links,function(i)
     read.xls(link, sheet = 1, perl = "C:\\Perl64\\bin\\perl.exe", header=TRUE) 
  )
}

data.frame, , , :

ll <- readxls()
do.call(rbind,ll)
+2

Source: https://habr.com/ru/post/1545214/


All Articles