Hi,
Suppose I have all the folders in my working directory.
?dir(recursive=T) #created two folders each with a single excel file
#[1] "Folder1/File1.xls" "Folder2/File2.xls"
library(XLConnect)
lst1 <- lapply(dir(recursive=T),function(x) {wb <- loadWorkbook(x); readWorksheet(wb,sheet="Sheet1")})
lst1
#[[1]]
#????????? State????? Lat???? Lon?????????????????????????? Address
#1 Anchorage USA 45.87576 -12.567 Starbucks, Van dyke road, 33456,
#2??? Albany USA 42.40000? 73.450?????? 1417, Central Avenue, 12205
#
#[[2]]
#????????? State?? Lat??? Lon????????????????????????? Address
#1?? Altanta USA 33.45? 84.23?????? 441, 16th street NW, 30363
#2 Anchorage USA 61.13 149.54 1140 W Parks Hwy, Wasilla, 99654
#3? Amarillo USA 35.11 101.50????????? 900, S. Harrison, 79101
do.call(rbind,lst1)
A.K.
I have about 10 folders in my directory i.e Folder 1 Folder 10. Each
Folder has a single excel file containing data with the following
attributes State,lat,lon, address i.e
State ? ? ? ? ? ? ? ? Lat ? ? ? ? ? ? ? ? ? Lon ? ? ? ? ? ? ? ? ? ?Address
Anchorage ? ?45.87576 ? ? -12.567 ? ? ? ? ?Starbucks, Van dyke road, 33456,
USA
I would like to write a script in R that goes through each folder and
gathers the data to create a single data frame that has all the data in
each folder. So I would have a single data frame that consists of all
observation appended together from in each excel file in each folder in one
data frame i.e?
State ? ? ? Lat ? ? ? ? ? ? ?Lon ? ? ? ? ? ? Address
xxx ? ? ? ? ?xxx ? ? ? ? ? ? ? xxx ? ? ? ? ? ? ?xxx
xxx ? ? ? ? ?xxx ? ? ? ? ? ? ? xxx ? ? ? ? ? ? ?xxx
xxx ? ? ? ? ?xxx ? ? ? ? ? ? ? xxx ? ? ? ? ? ? ?xxx
Please let me know how I would go about this
Vijay
Appending Excel File Data in different folders into Single Dataframe
1 message · arun