Read many Excel files from R -
it's first time r, maybe problem trivial
i need download date xls files url , each 1 should in 1 info frame. here .
i decided utilize gdata bundle (package ‘xlsreadwrite’ not available r version 3.1.0, rodbc not available win64)
downloading works great 1 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 read many .xls list() using loop. (e.g. y_begin=2012, y_end=2014)
readxls<-function() { library("gdata") ldata<<- list() j=1 (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 after i'd able merge them, don't know how info single info frame in list illustration > view(ldata[2]) returns first collumn
avoid utilize for
loop , specially side effect. improve utilize lapply
here. r way things ( functional programming). here this:
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) ) }
this homecoming list of data.frame, merge them, assuming ll same:
ll <- readxls() do.call(rbind,ll)
r excel
No comments:
Post a Comment