I'm new to R and am struggling to create a list of dataframes from imported Excel files.
I have a list of xls files I have imported into R using readxl.
First I got the paths of the xls files in the working directory:
filenames<- list.files(pattern=".xls")
Then I read in the xls files using lapply to create the list called "data"
data<-lapply(filenames, function(x) read_excel(path=x,sheet=1))
I had hoped each element of data would already be a dataframe as the read_excel function help seems to indicate but class(data[i]) indicates they are all individual lists (not sure why-- maybe due to use of lapply?).
I am now trying to convert each element (the data from each xls file) to a dataframe by using either lapply with as.data.frame or by using a for loop. Neither approach is working for me.
With the for loop the data frames are not coming out correctly:
data.df=NULL
for (i in 1:length(data)) {
data.df[i] = as.data.frame(data[i])
}
Another attempt with lapply that also does not result in a list of dataframes:
data.df<-lapply(data, function(x) as.data.frame(x))
What am I doing wrong?