I'm trying to load data from excel (from multiple files) into R using the xlsx package und converting the data into a xts object. The data should get as variable names the names of the related .xlsx sheet. The data has in the first column the dates and in the second a price.
My code so far:
path<-"C:/test/"
files<-list.files(path=path)
j<-1
for (i in files){
name<-strsplit(i,'[.]')[[1]][1]
assign(name,read.xlsx(file=paste(path,i,collapse=NULL,sep=""),sheetIndex=1,header=TRUE,as.data.frame=TRUE))
files[j]<-name
j<-j+1
}
Now I want to change the type to a xts object. But I don't know how to deal with the dates. One solution I found is to assign the first column as rowname but I don't know how to implement this without losing the variable names.
I would appreciate your help. Thx